Skip to content

Commit

Permalink
WIP: Support JDK 9 or later
Browse files Browse the repository at this point in the history
This allows SAW to deal with JDK 9 or later, which packages its standard
library not in a JAR file, but in a JIMAGE file. This leverages `crucible-jvm`
changes from GaloisInc/crucible#634.

This fixes #861.

Other things:

* I removed the dependency on the `xdg-basedir`, as it was unused. This
  dependency was likely added quite some time ago, and it appears that
  `saw-script` switched over to using XDG-related functionality from the
  `directory` library since then. I opted to use `directory` to find the
  `.cache` directory as well, so I have made that clear in the `.cabal` file.

* The `biJavaCodebase :: Codebase` field of `BuiltinContext` is completely
  unused, which I noticed when making changes to the `Codebase` type. Let's
  just remove it. This fixes #1003.
  • Loading branch information
RyanGlScott committed Feb 5, 2021
1 parent f8449a1 commit d6eae5e
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 126 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
matrix:
os: [ubuntu-18.04]
ghc: ["8.6.5", "8.8.4", "8.10.2"]
jdk: ["8", "15"]
continue-on-error: [false]
include:
- os: macos-latest
Expand Down Expand Up @@ -111,7 +112,7 @@ jobs:

- uses: actions/setup-java@v1
with:
java-version: "8"
java-version: ${{ matrix.jdk }}
java-package: jdk
architecture: x64

Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New Features

SAW now supports verifying Java code using JDK 9 or later.

When verifying Java code, the path to Java can be specified with the new
`--java-bin-dirs`/`-b` command-line option. Alternatively, if
`--java-bin-dirs` is not set, then SAW searches the `PATH` to find Java.
Expand Down
2 changes: 1 addition & 1 deletion deps/crucible
Submodule crucible updated 48 files
+5 −3 .github/ci.sh
+2 −0 .github/workflows/crux-llvm-build.yml
+2 −0 .github/workflows/crux-mir-build.yml
+8 −1 crucible-jvm/crucible-jvm.cabal
+232 −35 crucible-jvm/src/Lang/JVM/Codebase.hs
+93 −0 crucible-jvm/src/Lang/JVM/JavaTools.hs
+30 −0 crucible-jvm/src/Lang/JVM/ProcessUtils.hs
+ crucible-jvm/tests/Str.class
+5 −3 crucible-jvm/tests/ashes/README.md
+1 −3 crucible-jvm/tests/ashes/runcrucible.sh
+1 −4 crucible-jvm/tests/test.sh
+46 −11 crucible-jvm/tool/Main.hs
+1 −1 crucible-llvm/crucible-llvm.cabal
+21 −4 crucible-llvm/src/Lang/Crucible/LLVM/Translation.hs
+2 −2 crucible-llvm/test/Tests.hs
+1 −1 crux-llvm/crux-llvm.cabal
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/issue_478.result
+0 −1 crux-llvm/test-data/golden/golden-loop-merging/issue_478_unsafe.good
+1 −0 crux-llvm/test-data/golden/golden-loop-merging/issue_478_unsafe.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/loop_exit.result
+0 −1 crux-llvm/test-data/golden/golden-loop-merging/loop_exit_unsafe.good
+1 −0 crux-llvm/test-data/golden/golden-loop-merging/loop_exit_unsafe.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/loop_sequence.result
+0 −1 crux-llvm/test-data/golden/golden-loop-merging/loop_sequence_unsafe.good
+1 −0 crux-llvm/test-data/golden/golden-loop-merging/loop_sequence_unsafe.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/nested.result
+0 −1 crux-llvm/test-data/golden/golden-loop-merging/nested_unsafe.good
+1 −0 crux-llvm/test-data/golden/golden-loop-merging/nested_unsafe.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/string.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/string2.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/strlen_test.result
+0 −0 crux-llvm/test-data/golden/golden-loop-merging/strlen_test2.result
+0 −0 crux-llvm/test-data/golden/golden/float-cast.result
+0 −0 crux-llvm/test-data/golden/golden/float-cast2.result
+0 −0 crux-llvm/test-data/golden/golden/funnel.result
+0 −0 crux-llvm/test-data/golden/golden/gcd-test.result
+0 −0 crux-llvm/test-data/golden/golden/hello.result
+0 −0 crux-llvm/test-data/golden/golden/hello2.result
+0 −0 crux-llvm/test-data/golden/golden/printing.result
+0 −0 crux-llvm/test-data/golden/golden/string.result
+0 −0 crux-llvm/test-data/golden/golden/string2.result
+0 −0 crux-llvm/test-data/golden/golden/strlen_test.result
+0 −0 crux-llvm/test-data/golden/golden/strlen_test2.result
+0 −0 crux-llvm/test-data/golden/golden/uint-cast.result
+0 −0 crux-llvm/test-data/golden/golden/vector-cmp.result
+0 −0 crux-llvm/test-data/golden/golden/vector-gep.result
+0 −0 crux-llvm/test-data/golden/golden/vector-select.result
+238 −94 crux-llvm/test/Test.hs
5 changes: 1 addition & 4 deletions doc/manual/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1568,10 +1568,7 @@ the `java_load_class` function.
The resulting `JavaClass` can be passed into the various functions
described below to perform analysis of specific Java methods.

Java class files from any JDK newer than version 6 should work. However,
JDK version 9 and newer do not contain a JAR file containing the
standard libraries, and therefore do not currently work with SAW. We are
investigating the best way to resolve this issue.
Java class files from any JDK newer than version 6 should work.

## Notes on Compiling Code for SAW

Expand Down
5 changes: 1 addition & 4 deletions doc/tutorial/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ locates Java. Run the code in this section with the command:
Alternatively, if Java is located on your `PATH`, you can omit the `-b`
option entirely.

Both Oracle JDK and OpenJDK versions 6 through 8 work well with SAW.
From version 9 onward, the core libraries are no longer stored in a
standard JAR file, making them inacessible to SAW. We're currently
considering strategies for working with newer Java versions.
Both Oracle JDK and OpenJDK versions 6 and later work well with SAW.

Now we can do the proof both within and across languages (from
`ffs_compare.saw`):
Expand Down
6 changes: 5 additions & 1 deletion intTests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ for i in "$TESTBASE"/jars/*.jar; do
if [ "$OS" == "Windows_NT" ]; then
i=$(cygpath -w "$i")
fi
CP=$CP$CPSEP$i
if [ -z "$CP" ]; then
CP=$i
else
CP=$CP$CPSEP$i
fi
done
export CP

Expand Down
4 changes: 2 additions & 2 deletions saw-remote-api/src/SAWServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ initialState readFileFn =
ss <- basic_ss sc
let jarFiles = []
classPaths = []
jcb <- JSS.loadCodebase jarFiles classPaths
javaBinDirs = []
jcb <- JSS.loadCodebase jarFiles classPaths javaBinDirs
let bic = BuiltinContext { biSharedContext = sc
, biJavaCodebase = jcb
, biBasicSS = ss
}
cenv <- initCryptolEnv sc
Expand Down
3 changes: 0 additions & 3 deletions saw-script.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ library
, utf8-string
, what4 >= 0.4
, vector
, xdg-basedir
, GraphSCC
, macaw-base
, macaw-x86
Expand Down Expand Up @@ -115,15 +114,13 @@ library
SAWScript.ImportAIG
SAWScript.Interpreter
SAWScript.JavaExpr
SAWScript.JavaTools
SAWScript.JavaPretty
SAWScript.Lexer
SAWScript.LLVMBuiltins
SAWScript.Options
SAWScript.Panic
SAWScript.Parser
SAWScript.PathVC
SAWScript.ProcessUtils
SAWScript.Proof
SAWScript.Position
SAWScript.SBVParser
Expand Down
4 changes: 3 additions & 1 deletion src/SAWScript/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ import Verifier.SAW.TypedAST

import SAWScript.Position

-- crucible-jvm
import Lang.JVM.ProcessUtils

-- cryptol-saw-core
import qualified Verifier.SAW.CryptolEnv as CEnv

Expand Down Expand Up @@ -118,7 +121,6 @@ import SAWScript.ImportAIG

import SAWScript.AST (getVal, pShow, Located(..))
import SAWScript.Options as Opts
import SAWScript.ProcessUtils
import SAWScript.Proof
import SAWScript.TopLevel
import qualified SAWScript.Value as SV
Expand Down
3 changes: 1 addition & 2 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ buildTopLevelEnv proxy opts =
simps <- scSimpset sc0 cryptolDefs [] convs
let sc = rewritingSharedContext sc0 simps
ss <- basic_ss sc
jcb <- JCB.loadCodebase (jarList opts) (classPath opts)
jcb <- JCB.loadCodebase (jarList opts) (classPath opts) (javaBinDirs opts)
currDir <- getCurrentDirectory
Crucible.withHandleAllocator $ \halloc -> do
let ro0 = TopLevelRO
Expand All @@ -433,7 +433,6 @@ buildTopLevelEnv proxy opts =
}
let bic = BuiltinContext {
biSharedContext = sc
, biJavaCodebase = jcb
, biBasicSS = ss
}
primsAvail = Set.fromList [Current]
Expand Down
74 changes: 0 additions & 74 deletions src/SAWScript/JavaTools.hs

This file was deleted.

7 changes: 4 additions & 3 deletions src/SAWScript/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import System.IO
import Text.Read (readMaybe)
import Text.Show.Functions ()

import SAWScript.JavaTools
import Lang.JVM.JavaTools

-- TODO: wouldn't it be better to extract the options-processing code from this file and put it in saw/Main.hs (which already does part of the options processing)? It seems that other parts of SAW only need the datatype definition below, and not the rest.
data Options = Options
Expand Down Expand Up @@ -207,8 +207,9 @@ processEnv opts = do
-- --java-bin-dirs or PATH, see the Haddocks for findJavaIn), then use that
-- to detect the path to Java's standard rt.jar file and add it to the
-- jarList on Java 8 or earlier. (Later versions of Java do not use
-- rt.jar—see #861.) If Java's path is not specified, return the Options
-- unchanged.
-- rt.jar—see Note [Loading classes from JIMAGE files] in
-- Lang.JVM.Codebase in crucible-jvm.)
-- If Java's path is not specified, return the Options unchanged.
addJavaBinDirInducedOpts :: Options -> IO Options
addJavaBinDirInducedOpts os@Options{javaBinDirs} = do
mbJavaPath <- findJavaIn javaBinDirs
Expand Down
29 changes: 0 additions & 29 deletions src/SAWScript/ProcessUtils.hs

This file was deleted.

1 change: 0 additions & 1 deletion src/SAWScript/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ data SAW_CFG where
JVM_CFG :: Crucible.AnyCFG JVM -> SAW_CFG

data BuiltinContext = BuiltinContext { biSharedContext :: SharedContext
, biJavaCodebase :: JSS.Codebase
, biBasicSS :: Simpset
}
deriving Generic
Expand Down

0 comments on commit d6eae5e

Please sign in to comment.