diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b561f5c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -os: - - linux - - osx - -language: java - -env: - - GRAALVM_VERSION="20.0.0" GRAALVM_JAVA_VERSION="8" - - GRAALVM_VERSION="20.0.0" GRAALVM_JAVA_VERSION="11" - -install: - - cd .. && mv simpletool "simple tool" && cd "simple tool" - - | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then DOWNLOAD_OS_NAME="darwin"; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then DOWNLOAD_OS_NAME="linux"; fi - curl -LJ "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-$GRAALVM_VERSION/graalvm-ce-java$GRAALVM_JAVA_VERSION-$DOWNLOAD_OS_NAME-amd64-$GRAALVM_VERSION.tar.gz" --output graalvm.tar.gz - tar -xzf graalvm.tar.gz - export JAVA_HOME="$(pwd)/graalvm-ce-java$GRAALVM_JAVA_VERSION-$GRAALVM_VERSION" - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export JAVA_HOME="$JAVA_HOME/Contents/Home"; fi - -script: - - mvn package - - ./simpletool js example.js - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck simpletool; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then shellcheck runJsWithCoverage.sh; fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..90de6cb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +This repository contains a snapshot of SimpleTool that is updated only after major changes. The development version is part of the Truffle repository: https://github.com/graalvm/truffle diff --git a/README.md b/README.md index 590bb84..cde1547 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Simple Tool -A simple demonstration code coverage tool built using Truffle for the GraalVM. +A simple demonstration code coverage tool built using Truffle for GraalVM. The source code is documented to explain the how and why of writing a Truffle tool. A good way to find out more is to read the source with comments. We also @@ -9,5 +9,4 @@ like to encourage people to clone the repository and start hacking. This repository is licensed under the permissive UPL licence. Fork it to begin your own Truffle tool. -For instructions on how to get started please refer to [our -website](https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/) +For instructions on how to get started please refer to [our website](https://www.graalvm.org/docs/graalvm-as-a-platform/implement-instrument/) diff --git a/ci.jsonnet b/ci.jsonnet index d38e6eb..3fabe01 100644 --- a/ci.jsonnet +++ b/ci.jsonnet @@ -5,14 +5,14 @@ run: [ ['mvn', 'clean'], ['mvn', 'package'], - ['./simpletool', 'js', 'example.js'], + ['./simpletool', 'example.js'], ], }, local graalvm = { - downloads+: { - JAVA_HOME: { name: 'graalvm', version: '20.0.0', platformspecific: true }, - }, + downloads+: { + JAVA_HOME: { name: 'graalvm-community-java21', version: '23.1.0', platformspecific: true }, + }, }, local linux = { @@ -20,12 +20,17 @@ packages+: { maven: '==3.3.9', }, + docker: { + image: "buildslave_ol7", + mount_modules: true, + }, }, local darwin = { capabilities+: ['darwin_sierra', 'amd64'], environment+: { MACOSX_DEPLOYMENT_TARGET: '10.11', + JAVA_HOME: '$JAVA_HOME/Contents/Home' }, }, diff --git a/copy_from_graal.py b/copy_from_graal.py deleted file mode 100644 index 4ffaebe..0000000 --- a/copy_from_graal.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Since Simple Tool is not developed on this repository, we need to periodically sync this repository with the developement one. -# This scipt automates cloning the source repository and copying the ST code from there to here. -# Requires git to be installed. - -import os -import sys -from subprocess import call - -GRAAL_REPO = "https://github.com/oracle/graal" -GRAAL_DIR = "../" + GRAAL_REPO.split('/')[-1] - -def fail(message): - """ Print message to stderr and exit script - - """ - print >> sys.stderr, message - sys.exit(1) - -def clone(repo, path = ""): - """ Clones the given repo url using git - - :repo: String containing the url - - """ - if call(["git", "clone", repo, path]) != 0: - fail("Could not clone " + repo) - pass - -def checkout(path, commit, create = False): - """ Checks out a new branch in SL - - :cwd: path to the git repo - :commit: String, name for the new branch - :create: create new or expect it to exist - - """ - command = ["git", "checkout"] - if create: - command.append("-b") - command.append(commit) - if call(command, cwd=path) != 0: - fail("Could not checkout " + commit + " from " + path) - -def replace(source, dest): - """ Replace contents of dest dir with contents of source dir - - :source: String path to source - :dest: String path do destination - - """ - call(["rm", "-rf", dest]) - call(["mkdir", "-p", dest]) - call(["cp", "-RTf", source, dest]) - -def copy_st(): - """ Copies ST from graal to simpletool - - """ - replace(GRAAL_DIR + "/truffle/src/com.oracle.truffle.st/src/com" , "src/main/java/com") - replace(GRAAL_DIR + "/truffle/src/com.oracle.truffle.st.test/src/com" , "src/test/java/com") - -def update_st(revision): - """ Updates the SL repo from the graal repo given a revision - - :revision: the hash of the commit in the graal repo to be used - - """ - checkout(".", "st_update_"+revision, True) - if os.path.isdir(GRAAL_DIR): - call(['git', 'fetch'], cwd=GRAAL_DIR) - else: - clone(GRAAL_REPO, GRAAL_DIR) - checkout(GRAAL_DIR, revision) - copy_st() - print "" - print "NOTE: Update the version in st, README.md and all pom.xml files!" - print "NOTE: Follow the instructions in README.md and make sure mvn package executes correctly!" - print "NOTE: Make sure project open correctly on the supported IDEs!" - print "" - -if __name__ == "__main__": - if (len(sys.argv) != 2): - fail("usage: " + sys.argv[0] + " idOfGraalCommitToUseAsBase") - update_st(sys.argv[1]) diff --git a/example.js b/example.js index 0ebc9d3..68b719c 100644 --- a/example.js +++ b/example.js @@ -1,3 +1,43 @@ +/* + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ var N = 2000; var EXPECTED = 17393; diff --git a/pom.xml b/pom.xml index 1aaca8f..fd4171e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,78 +1,71 @@ - - 4.0.0 + + + 4.0.0 com.oracle simpletool - 20.0.0 - + ${graalvm.version} simpletool - + 23.1.0 UTF-8 - 1.8 - 1.8 - 20.0.0 + 17 + 17 + jdt_apt - - - jdk11-graalvm - - [11, - - - ${project.build.directory}/jars - --upgrade-module-path=${jar.dir}/truffle-api.jar - - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.10 - - - copy - process-test-classes - - copy - - - - - org.graalvm.truffle - truffle-api - ${graalvm.version} - jar - true - truffle-api.jar - - - ${jar.dir} - - - - - - - - - jdk8-graalvm - - 1.8 - - - -XX:-UseJVMCIClassLoader - - - junit junit - 4.11 + 4.13.2 test + + org.graalvm.polyglot + polyglot + ${graalvm.version} + org.graalvm.truffle truffle-api @@ -80,34 +73,72 @@ org.graalvm.truffle - truffle-dsl-processor + truffle-runtime + ${graalvm.version} + runtime + + + org.graalvm.sdk + jniutils ${graalvm.version} + runtime + org.graalvm.js - js + js-language + ${graalvm.version} + runtime + + + org.graalvm.js + js-launcher ${graalvm.version} - test - - - - - maven-compiler-plugin - 3.8.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 2.9 - - - -Dgraalvm.locatorDisabled=true ${test.argLine} - - - - + + + org.apache.maven.plugins + maven-dependency-plugin + 3.2.0 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/modules + true + + + + + + maven-compiler-plugin + 3.11.0 + + 17 + 17 + + + org.graalvm.truffle + truffle-dsl-processor + ${graalvm.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + true + + + diff --git a/runJsWithCoverage.sh b/runJsWithCoverage.sh index 89df7da..fceab27 100755 --- a/runJsWithCoverage.sh +++ b/runJsWithCoverage.sh @@ -1,2 +1,43 @@ -#!/bin/bash -./simpletool js example.js +#!/usr/bin/env bash +# +# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# The Universal Permissive License (UPL), Version 1.0 +# +# Subject to the condition set forth below, permission is hereby granted to any +# person obtaining a copy of this software, associated documentation and/or +# data (collectively the "Software"), free of charge and under any and all +# copyright rights in the Software, and any and all patent rights owned or +# freely licensable by each licensor hereunder covering either (i) the +# unmodified Software as contributed to or provided by such licensor, or (ii) +# the Larger Works (as defined below), to deal in both +# +# (a) the Software, and +# +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +# one is included with the Software each a "Larger Work" to which the Software +# is contributed by such licensors), +# +# without restriction, including without limitation the rights to copy, create +# derivative works of, display, perform, and distribute the Software and make, +# use, sell, offer for sale, import, export, have made, and have sold the +# Software and the Larger Work(s), and to sublicense the foregoing rights on +# either these or other terms. +# +# This license is subject to the following condition: +# +# The above copyright notice and either this complete permission notice or at a +# minimum a reference to the UPL must be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +./simpletool example.js diff --git a/simpletool b/simpletool index 77e58cb..ed4ec93 100755 --- a/simpletool +++ b/simpletool @@ -1,20 +1,45 @@ -#!/bin/bash +#!/usr/bin/env bash +# +# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# The Universal Permissive License (UPL), Version 1.0 +# +# Subject to the condition set forth below, permission is hereby granted to any +# person obtaining a copy of this software, associated documentation and/or +# data (collectively the "Software"), free of charge and under any and all +# copyright rights in the Software, and any and all patent rights owned or +# freely licensable by each licensor hereunder covering either (i) the +# unmodified Software as contributed to or provided by such licensor, or (ii) +# the Larger Works (as defined below), to deal in both +# +# (a) the Software, and +# +# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +# one is included with the Software each a "Larger Work" to which the Software +# is contributed by such licensors), +# +# without restriction, including without limitation the rights to copy, create +# derivative works of, display, perform, and distribute the Software and make, +# use, sell, offer for sale, import, export, have made, and have sold the +# Software and the Larger Work(s), and to sublicense the foregoing rights on +# either these or other terms. +# +# This license is subject to the following condition: +# +# The above copyright notice and either this complete permission notice or at a +# minimum a reference to the UPL must be included in all copies or substantial +# portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# -function printUsage() { - echo "Usage:" - echo "$0 " - echo "Example:" - echo "$0 js example.js" - exit 0 -} - -[ -z "$1" ] || [ "$1" == "--help" ] || [ "$1" == "-help" ] && printUsage - -LAUNCHER=$1 -shift - -"$JAVA_HOME/bin/$LAUNCHER" \ - --jvm \ - --vm.Dtruffle.class.path.append=target/simpletool-20.0.0.jar \ - --simple-code-coverage \ - "$@" +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +"$JAVA_HOME/bin/java" -p "${DIR}/target/modules:${DIR}/target/classes" -m org.graalvm.js.launcher/com.oracle.truffle.js.shell.JSLauncher --simple-code-coverage "$@" \ No newline at end of file diff --git a/src/main/java/com/oracle/truffle/st/SimpleCoverageInstrument.java b/src/main/java/com/oracle/truffle/st/SimpleCoverageInstrument.java index af8ee89..1a302e6 100644 --- a/src/main/java/com/oracle/truffle/st/SimpleCoverageInstrument.java +++ b/src/main/java/com/oracle/truffle/st/SimpleCoverageInstrument.java @@ -179,7 +179,7 @@ private void enable(final Env env) { * @param env */ @Override - protected void onDispose(Env env) { + protected void onFinalize(Env env) { if (PRINT_COVERAGE.getValue(env.getOptions())) { printResults(env); } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 0000000..a967e31 --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +module org.graalvm.st { + requires java.base; + requires java.logging; + requires jdk.unsupported; + requires org.graalvm.polyglot; + requires org.graalvm.truffle; + exports com.oracle.truffle.st to org.graalvm.st.test; + provides com.oracle.truffle.api.instrumentation.provider.TruffleInstrumentProvider with + com.oracle.truffle.st.SimpleCoverageInstrumentProvider; +} diff --git a/src/test/java/module-info.java b/src/test/java/module-info.java new file mode 100644 index 0000000..c65618d --- /dev/null +++ b/src/test/java/module-info.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or + * data (collectively the "Software"), free of charge and under any and all + * copyright rights in the Software, and any and all patent rights owned or + * freely licensable by each licensor hereunder covering either (i) the + * unmodified Software as contributed to or provided by such licensor, or (ii) + * the Larger Works (as defined below), to deal in both + * + * (a) the Software, and + * + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * + * The above copyright notice and either this complete permission notice or at a + * minimum a reference to the UPL must be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +open module org.graalvm.st.test { + requires java.logging; + requires jdk.unsupported; + requires org.graalvm.polyglot; + requires junit; + requires org.graalvm.truffle; + requires org.graalvm.st; + exports com.oracle.truffle.st.test; + +}