├── .github ├── FUNDING.yml └── workflows │ ├── [A] build and test, release if requested.yml │ ├── [A] update documentation.yml │ └── [M] build and test, release if requested.yml ├── .gitignore ├── LICENSE ├── README.md ├── docs ├── _config.yml ├── _layouts │ └── default.html ├── assets │ ├── css │ │ └── style.scss │ └── fonts │ │ ├── AldoPro-Black.ttf │ │ ├── AldoPro-Black.woff │ │ ├── AldoPro-Black.woff2 │ │ ├── AldoPro-Bold.ttf │ │ ├── AldoPro-Bold.woff │ │ ├── AldoPro-Bold.woff2 │ │ ├── AldoPro-Book.ttf │ │ ├── AldoPro-Book.woff │ │ ├── AldoPro-Book.woff2 │ │ ├── AldoPro-Hairline.ttf │ │ ├── AldoPro-Hairline.woff │ │ ├── AldoPro-Hairline.woff2 │ │ ├── AldoPro-Light.ttf │ │ ├── AldoPro-Light.woff │ │ ├── AldoPro-Light.woff2 │ │ ├── AldoPro-Medium.ttf │ │ ├── AldoPro-Medium.woff │ │ ├── AldoPro-Medium.woff2 │ │ ├── AldoPro-Regular.ttf │ │ ├── AldoPro-Regular.woff │ │ ├── AldoPro-Regular.woff2 │ │ ├── AldoPro-Thin.ttf │ │ ├── AldoPro-Thin.woff │ │ └── AldoPro-Thin.woff2 └── index.md ├── java ├── pom.xml ├── sa-pom.xml └── src │ ├── main │ ├── java │ │ ├── module-info.java │ │ └── org │ │ │ └── burningwave │ │ │ └── jvm │ │ │ ├── DynamicDriver.java │ │ │ ├── HybridDriver.java │ │ │ ├── NativeDriver.java │ │ │ ├── NativeExecutor.java │ │ │ ├── function │ │ │ └── catalog │ │ │ │ ├── AllocateInstanceFunction.java │ │ │ │ ├── ConsulterSupplier.java │ │ │ │ ├── ConsulterSupplyFunction.java │ │ │ │ ├── GetFieldValueFunction.java │ │ │ │ ├── GetLoadedClassesRetrieverFunction.java │ │ │ │ ├── GetLoadedPackagesFunction.java │ │ │ │ ├── SetAccessibleFunction.java │ │ │ │ └── SetFieldValueFunction.java │ │ │ └── util │ │ │ ├── Files.java │ │ │ ├── Libraries.java │ │ │ └── TempFileHolder.java │ └── resources │ │ └── jvm-driver.properties │ └── test │ └── java │ └── org │ └── burningwave │ └── jvm │ └── test │ ├── AllTestsSuite.java │ ├── BaseTest.java │ ├── DefaultDriverTest.java │ ├── DynamicDriverTest.java │ ├── HybridDriverTest.java │ ├── NativeDriverTest.java │ ├── NativeExecutorTest.java │ └── Reflection.java ├── launcher └── eclipse │ ├── Burningwave JVM Driver - Debug attacher.launch │ ├── Burningwave JVM Driver - build and test with REMOTE DEBUG.launch │ ├── Burningwave JVM Driver - parent clean package install.launch │ └── Burningwave JVM Driver - test.launch ├── native ├── bin │ ├── NativeExecutor-x32.dll │ ├── NativeExecutor-x64.dll │ ├── libNativeExecutor-aarch64.so │ ├── libNativeExecutor-x32.so │ ├── libNativeExecutor-x64.dylib │ └── libNativeExecutor-x64.so ├── pom.xml └── src │ └── main │ └── c-c++ │ └── org │ └── burningwave │ ├── common.h │ └── jvm │ ├── NativeEnvironment.cpp │ ├── NativeEnvironment.h │ ├── NativeExecutor.cpp │ └── NativeExecutor.h └── pom.xml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: https://www.paypal.com/donate/?cmd=_donations&business=EY4TMTW8SWDAC&item_name=Support+maintenance+and+improvement+of+Burningwave+JVM+Driver¤cy_code=EUR&source=url 2 | -------------------------------------------------------------------------------- /.github/workflows/[A] build and test, release if requested.yml: -------------------------------------------------------------------------------- 1 | name: Build and release if requested 2 | 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | paths: 9 | - "**.sh" 10 | - "**.cmd" 11 | - "**.c" 12 | - "**.cpp" 13 | - "**.java" 14 | # - ".github/workflows/**" 15 | - "**.properties" 16 | - "**.xml" 17 | 18 | 19 | jobs: 20 | 21 | 22 | elaborate-native-module: 23 | name: Elaborate native module (${{ matrix.os }} ${{ matrix.architecture }}) 24 | strategy: 25 | fail-fast: false 26 | max-parallel: 2 27 | matrix: 28 | os: [windows-latest, ubuntu-22.04, macos-latest] 29 | java: [19] 30 | distribution: [zulu] 31 | architecture: [x86, x64] 32 | exclude: 33 | - os: macOS-latest 34 | architecture: x86 35 | runs-on: ${{ matrix.os }} 36 | steps: 37 | - name: Set up JDK ${{ matrix.java }} 38 | uses: actions/setup-java@v3 39 | with: 40 | java-version: ${{ matrix.java }} 41 | distribution: 'zulu' 42 | architecture: ${{ matrix.architecture }} 43 | - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.architecture, 'x64') 44 | name: Set up C/C++ compiler 45 | run: | 46 | sudo apt update 47 | sudo apt-get -y install g++-aarch64-linux-gnu g++-arm-linux-gnueabi 48 | - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.architecture, 'x86') 49 | name: Set up C/C++ compiler 50 | run: | 51 | sudo apt update 52 | sudo apt-get -y install doxygen vera++ zlib1g-dev libsnappy-dev \ 53 | g++-multilib 54 | - if: startsWith(matrix.os, 'windows-latest') && startsWith(matrix.architecture, 'x86') 55 | name: Set up C/C++ compiler 56 | uses: egor-tensin/setup-mingw@v2 57 | with: 58 | platform: ${{ matrix.architecture }} 59 | version: 12.2.0 60 | - uses: actions/checkout@v3 61 | - name: Build native library 62 | run: mvn -B clean compile -Dproject_jdk_version=${{ matrix.java }} -DskipTests=true --file ./native/pom.xml 63 | - if: startsWith(matrix.os, 'ubuntu-22.04') && startsWith(matrix.architecture, 'x64') 64 | name: Build native library for platform group one 65 | run: | 66 | mvn -B clean compile -Dproject_jdk_version=${{ matrix.java }} -Pextra-compilation-one -Dextra-compilation-one-executable=aarch64-linux-gnu-g++ -Dextra-compilation-one-artifact-name-suffix=aarch64 -DskipTests=true --file ./native/pom.xml 67 | # mvn -B clean compile -Dproject_jdk_version=${{ matrix.java }} -Pextra-compilation-one -Dextra-compilation-one-executable=arm-linux-gnueabi-g++ -Dextra-compilation-one-artifact-name-suffix=armeabi-x32 -DskipTests=true --file ./native/pom.xml 68 | - if: github.event_name == 'push' && (endsWith(github.event.head_commit.message, 'Releasing new version') || contains(github.event.head_commit.message, 'Generating external artifacts')) 69 | name: Push native library 70 | run: | 71 | git config user.name "${{ github.event.head_commit.committer.name }}" 72 | git config user.email "${{ github.event.head_commit.committer.email }}" 73 | git pull origin ${{github.ref}} 74 | git add . 75 | git commit -am "Generated native libraries on ${{ matrix.os }} ${{ matrix.architecture }}" --allow-empty 76 | git push 77 | 78 | build-and-test-with-zulu-JDK: 79 | name: ${{ matrix.os }} ${{ matrix.architecture }}, JVM ${{ matrix.distribution }} ${{ matrix.java }} 80 | needs: [elaborate-native-module] 81 | strategy: 82 | fail-fast: false 83 | max-parallel: 15 84 | matrix: 85 | architecture: [x64] 86 | distribution: [zulu] 87 | os: [ubuntu-latest, macOS-latest, windows-latest] 88 | java: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] 89 | exclude: 90 | - architecture: x64 91 | java: 10 92 | runs-on: ${{ matrix.os }} 93 | steps: 94 | - uses: actions/checkout@v3 95 | - name: Set up JDK ${{ matrix.java }} 96 | uses: actions/setup-java@v3 97 | with: 98 | java-version: ${{ matrix.java }} 99 | distribution: ${{ matrix.distribution }} 100 | architecture: ${{ matrix.architecture }} 101 | - name: Update repositories 102 | run: | 103 | git config user.name "${{ github.event.head_commit.committer.name }}" 104 | git config user.email "${{ github.event.head_commit.committer.email }}" 105 | git pull origin ${{github.ref}} 106 | - name: Build and test with Java 7 target 107 | if: ${{ fromJSON(matrix.java) <= 19 }} 108 | run: mvn -B clean test -DskipTests=false --file ./java/pom.xml 109 | - name: Build and test with Java 8 target 110 | if: ${{ fromJSON(matrix.java) > 19}} 111 | run: mvn -B clean test -Dproject_jdk_version=8 -DskipTests=false --file ./java/pom.xml 112 | 113 | 114 | build-and-test-with-semeru-JDK: 115 | name: ${{ matrix.os }} ${{ matrix.architecture }}, JVM ${{ matrix.distribution }} ${{ matrix.java }} 116 | needs: [elaborate-native-module] 117 | strategy: 118 | fail-fast: false 119 | max-parallel: 15 120 | matrix: 121 | architecture: [x64] 122 | distribution: [semeru] 123 | os: [ubuntu-latest, macOS-latest, windows-latest] 124 | java: [11, 16, 17, 18, 19, 20, 21, 22, 23] 125 | runs-on: ${{ matrix.os }} 126 | steps: 127 | - uses: actions/checkout@v3 128 | - name: Set up JDK ${{ matrix.java }} 129 | uses: actions/setup-java@v3 130 | with: 131 | java-version: ${{ matrix.java }} 132 | distribution: ${{ matrix.distribution }} 133 | architecture: ${{ matrix.architecture }} 134 | - name: Update repositories 135 | run: | 136 | git config user.name "${{ github.event.head_commit.committer.name }}" 137 | git config user.email "${{ github.event.head_commit.committer.email }}" 138 | git pull origin ${{github.ref}} 139 | - name: Build and test with Java 7 target 140 | if: ${{ fromJSON(matrix.java) <= 19 }} 141 | run: mvn -B clean test -DskipTests=false --file ./java/pom.xml 142 | - name: Build and test with Java 8 target 143 | if: ${{ fromJSON(matrix.java) > 19}} 144 | run: mvn -B clean test -Dproject_jdk_version=8 -DskipTests=false --file ./java/pom.xml 145 | 146 | 147 | build-and-test-with-temurin-JDK: 148 | name: ${{ matrix.os }} ${{ matrix.architecture }}, JVM ${{ matrix.distribution }} ${{ matrix.java }} 149 | needs: [elaborate-native-module] 150 | strategy: 151 | fail-fast: false 152 | max-parallel: 15 153 | matrix: 154 | architecture: [x64] 155 | distribution: [temurin] 156 | os: [ubuntu-latest, macOS-latest, windows-latest] 157 | java: [11, 16, 17, 18, 19, 20, 21, 22, 23, 24] 158 | runs-on: ${{ matrix.os }} 159 | steps: 160 | - uses: actions/checkout@v3 161 | - name: Set up JDK ${{ matrix.java }} 162 | uses: actions/setup-java@v3 163 | with: 164 | java-version: ${{ matrix.java }} 165 | distribution: ${{ matrix.distribution }} 166 | architecture: ${{ matrix.architecture }} 167 | - name: Update repositories 168 | run: | 169 | git config user.name "${{ github.event.head_commit.committer.name }}" 170 | git config user.email "${{ github.event.head_commit.committer.email }}" 171 | git pull origin ${{github.ref}} 172 | - name: Build and test with Java 7 target 173 | if: ${{ fromJSON(matrix.java) <= 19 }} 174 | run: mvn -B clean test -DskipTests=false --file ./java/pom.xml 175 | - name: Build and test with Java 8 target 176 | if: ${{ fromJSON(matrix.java) > 19}} 177 | run: mvn -B clean test -Dproject_jdk_version=8 -DskipTests=false --file ./java/pom.xml 178 | 179 | 180 | #To ensure compatibility with the Java 7 version the build must never be run with a JDK version higher than 19 181 | release: 182 | needs: [build-and-test-with-zulu-JDK, build-and-test-with-semeru-JDK, build-and-test-with-temurin-JDK] 183 | name: Release if requested 184 | runs-on: ubuntu-latest 185 | if: github.event_name == 'push' && endsWith(github.event.head_commit.message, 'Releasing new version') 186 | steps: 187 | - uses: actions/checkout@v3 188 | - name: Set up JDK 19 189 | uses: actions/setup-java@v3 190 | with: 191 | java-version: 19 192 | distribution: 'zulu' 193 | server-id: ossrh 194 | server-username: MAVEN_USERNAME 195 | server-password: MAVEN_PASSWORD 196 | - name: Publish to the Maven central repository 197 | run: | 198 | export GPG_TTY=$(tty) 199 | echo "${{ secrets.gpg_private_key }}" | gpg --batch --import 200 | git config user.name "${{ github.event.head_commit.committer.name }}" 201 | git config user.email "${{ github.event.head_commit.committer.email }}" 202 | git pull origin ${{github.ref}} 203 | mv ./java/pom.xml ./java/temp-pom.xml 204 | mv ./java/sa-pom.xml ./java/pom.xml 205 | mv ./java/temp-pom.xml ./java/sa-pom.xml 206 | git commit -am "Swithcing pom for releasing" 207 | git push 208 | mvn -B release:prepare release:perform -DskipTests=true -Dgpg.passphrase=${{ secrets.gpg_passphrase }} -Dgpg.keyname=${{ secrets.gpg_key_id }} -Drepository.url=https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git --file ./java/pom.xml 209 | mv ./java/pom.xml ./java/temp-pom.xml 210 | mv ./java/sa-pom.xml ./java/pom.xml 211 | mv ./java/temp-pom.xml ./java/sa-pom.xml 212 | newVersion=$(sed -n -r 's%.*[[:space:]]*(.*-SNAPSHOT).*%\1%p' ./java/sa-pom.xml) 213 | sed -r -i "s%[[:space:]]*(.*-SNAPSHOT)%${newVersion}%" ./java/pom.xml 214 | git commit -am "Prepare for next development iteration" 215 | git push 216 | env: 217 | MAVEN_USERNAME: ${{ secrets.nexus_username }} 218 | MAVEN_PASSWORD: ${{ secrets.nexus_password }} -------------------------------------------------------------------------------- /.github/workflows/[A] update documentation.yml: -------------------------------------------------------------------------------- 1 | # This file is derived from ToolFactory JVM driver. 2 | # 3 | # Hosted at: https://github.com/toolfactory/jvm-driver 4 | # 5 | # Modified by: Roberto Gentili 6 | # 7 | # Modifications hosted at: https://github.com/burningwave/jvm-driver 8 | # 9 | # - - 10 | # 11 | # The MIT License (MIT) 12 | # 13 | # Copyright (c) 2021 Luke Hutchison, Roberto Gentili 14 | # 15 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 16 | # documentation files (the "Software"), to deal in the Software without restriction, including without 17 | # limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 18 | # the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 19 | # conditions: 20 | # 21 | # The above copyright notice and this permission notice shall be included in all copies or substantial 22 | # portions of the Software. 23 | # 24 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 25 | # LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 26 | # EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 27 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 28 | # OR OTHER DEALINGS IN THE SOFTWARE. 29 | # 30 | name: Update index page 31 | 32 | on: 33 | push: 34 | branches: 35 | - main 36 | paths: 37 | - "**README.md" 38 | 39 | jobs: 40 | update-index-page: 41 | runs-on: ubuntu-latest 42 | name: Update index page 43 | steps: 44 | - uses: actions/checkout@master 45 | - name: Overwrite the index.md 46 | run: | 47 | git config user.name "${{ github.event.head_commit.committer.name }}" 48 | git config user.email "${{ github.event.head_commit.committer.email }}" 49 | git pull origin ${{github.ref}} 50 | cp "./README.md" "./docs/index.md" 51 | git add . 52 | git commit -am "Update" --allow-empty 53 | git push 54 | -------------------------------------------------------------------------------- /.github/workflows/[M] build and test, release if requested.yml: -------------------------------------------------------------------------------- 1 | name: Build and test -> Release 2 | 3 | 4 | on: 5 | watch: 6 | types: [started] 7 | 8 | 9 | jobs: 10 | 11 | ask-for-authorization: 12 | name: Ask for authorization 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: octokit/request-action@v2.0.0 16 | with: 17 | route: GET /repos/:repository/collaborators/${{ github.actor }} 18 | repository: ${{ github.repository }} 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 21 | - name: Send push notification 22 | if: ${{ failure() }} 23 | uses: techulus/push-github-action@1.0.0 24 | env: 25 | API_KEY: ${{ secrets.PUSH_NOTIFICATION_API_KEY }} 26 | MESSAGE: ${{ format('New star for {0}!', github.repository) }} 27 | 28 | elaborate-native-module: 29 | needs: [ask-for-authorization] 30 | name: Elaborate native module (${{ matrix.os }} ${{ matrix.architecture }}) 31 | strategy: 32 | fail-fast: false 33 | max-parallel: 2 34 | matrix: 35 | os: [windows-latest, ubuntu-22.04, macos-latest] 36 | java: [19] 37 | distribution: [zulu] 38 | architecture: [x86, x64] 39 | exclude: 40 | - os: macOS-latest 41 | architecture: x86 42 | runs-on: ${{ matrix.os }} 43 | steps: 44 | - name: Set up JDK ${{ matrix.java }} 45 | uses: actions/setup-java@v3 46 | with: 47 | java-version: ${{ matrix.java }} 48 | distribution: 'zulu' 49 | architecture: ${{ matrix.architecture }} 50 | - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.architecture, 'x64') 51 | name: Set up C/C++ compiler 52 | run: | 53 | sudo apt update 54 | sudo apt-get -y install g++-aarch64-linux-gnu g++-arm-linux-gnueabi 55 | - if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.architecture, 'x86') 56 | name: Set up C/C++ compiler 57 | run: | 58 | sudo apt update 59 | sudo apt-get -y install doxygen vera++ zlib1g-dev libsnappy-dev \ 60 | g++-multilib 61 | - if: startsWith(matrix.os, 'windows-latest') && startsWith(matrix.architecture, 'x86') 62 | name: Set up C/C++ compiler 63 | uses: egor-tensin/setup-mingw@v2 64 | with: 65 | platform: ${{ matrix.architecture }} 66 | version: 12.2.0 67 | - uses: actions/checkout@v3 68 | - name: Build native library 69 | run: mvn -B clean compile -Dproject_jdk_version=${{ matrix.java }} -DskipTests=true --file ./native/pom.xml 70 | - if: startsWith(matrix.os, 'ubuntu-22.04') && startsWith(matrix.architecture, 'x64') 71 | name: Build native library for platform group one 72 | run: | 73 | mvn -B clean compile -Dproject_jdk_version=${{ matrix.java }} -Pextra-compilation-one -Dextra-compilation-one-executable=aarch64-linux-gnu-g++ -Dextra-compilation-one-artifact-name-suffix=aarch64 -DskipTests=true --file ./native/pom.xml 74 | # mvn -B clean compile -Dproject_jdk_version=${{ matrix.java }} -Pextra-compilation-one -Dextra-compilation-one-executable=arm-linux-gnueabi-g++ -Dextra-compilation-one-artifact-name-suffix=armeabi-x32 -DskipTests=true --file ./native/pom.xml 75 | - name: Push native library 76 | run: | 77 | git config user.name "burningwave" 78 | git config user.email "info@burningwave.org" 79 | git pull origin ${{github.ref}} 80 | git add . 81 | git commit -am "Generated native libraries on ${{ matrix.os }} ${{ matrix.architecture }}" --allow-empty 82 | git push 83 | 84 | build-and-test-with-zulu-JDK: 85 | name: ${{ matrix.os }} ${{ matrix.architecture }}, JVM ${{ matrix.distribution }} ${{ matrix.java }} 86 | needs: [elaborate-native-module] 87 | strategy: 88 | fail-fast: false 89 | max-parallel: 15 90 | matrix: 91 | architecture: [x64] 92 | distribution: [zulu] 93 | os: [ubuntu-latest, macOS-latest, windows-latest] 94 | java: [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] 95 | exclude: 96 | - architecture: x64 97 | java: 10 98 | runs-on: ${{ matrix.os }} 99 | steps: 100 | - uses: actions/checkout@v3 101 | - name: Set up JDK ${{ matrix.java }} 102 | uses: actions/setup-java@v3 103 | with: 104 | java-version: ${{ matrix.java }} 105 | distribution: ${{ matrix.distribution }} 106 | architecture: ${{ matrix.architecture }} 107 | - name: Update repositories 108 | run: | 109 | git config user.name "${{ github.event.head_commit.committer.name }}" 110 | git config user.email "${{ github.event.head_commit.committer.email }}" 111 | git pull origin ${{github.ref}} 112 | - name: Build and test with Java 7 target 113 | if: ${{ fromJSON(matrix.java) <= 19 }} 114 | run: mvn -B clean test -DskipTests=false --file ./java/pom.xml 115 | - name: Build and test with Java 8 target 116 | if: ${{ fromJSON(matrix.java) > 19}} 117 | run: mvn -B clean test -Dproject_jdk_version=8 -DskipTests=false --file ./java/pom.xml 118 | 119 | 120 | build-and-test-with-semeru-JDK: 121 | name: ${{ matrix.os }} ${{ matrix.architecture }}, JVM ${{ matrix.distribution }} ${{ matrix.java }} 122 | needs: [elaborate-native-module] 123 | strategy: 124 | fail-fast: false 125 | max-parallel: 15 126 | matrix: 127 | architecture: [x64] 128 | distribution: [semeru] 129 | os: [ubuntu-latest, macOS-latest, windows-latest] 130 | java: [11, 16, 17, 18, 19, 20, 21, 22, 23] 131 | runs-on: ${{ matrix.os }} 132 | steps: 133 | - uses: actions/checkout@v3 134 | - name: Set up JDK ${{ matrix.java }} 135 | uses: actions/setup-java@v3 136 | with: 137 | java-version: ${{ matrix.java }} 138 | distribution: ${{ matrix.distribution }} 139 | architecture: ${{ matrix.architecture }} 140 | - name: Update repositories 141 | run: | 142 | git config user.name "${{ github.event.head_commit.committer.name }}" 143 | git config user.email "${{ github.event.head_commit.committer.email }}" 144 | git pull origin ${{github.ref}} 145 | - name: Build and test with Java 7 target 146 | if: ${{ fromJSON(matrix.java) <= 19 }} 147 | run: mvn -B clean test -DskipTests=false --file ./java/pom.xml 148 | - name: Build and test with Java 8 target 149 | if: ${{ fromJSON(matrix.java) > 19}} 150 | run: mvn -B clean test -Dproject_jdk_version=8 -DskipTests=false --file ./java/pom.xml 151 | 152 | 153 | build-and-test-with-temurin-JDK: 154 | name: ${{ matrix.os }} ${{ matrix.architecture }}, JVM ${{ matrix.distribution }} ${{ matrix.java }} 155 | needs: [elaborate-native-module] 156 | strategy: 157 | fail-fast: false 158 | max-parallel: 15 159 | matrix: 160 | architecture: [x64] 161 | distribution: [temurin] 162 | os: [ubuntu-latest, macOS-latest, windows-latest] 163 | java: [11, 16, 17, 18, 19, 20, 21, 22, 23, 24] 164 | runs-on: ${{ matrix.os }} 165 | steps: 166 | - uses: actions/checkout@v3 167 | - name: Set up JDK ${{ matrix.java }} 168 | uses: actions/setup-java@v3 169 | with: 170 | java-version: ${{ matrix.java }} 171 | distribution: ${{ matrix.distribution }} 172 | architecture: ${{ matrix.architecture }} 173 | - name: Update repositories 174 | run: | 175 | git config user.name "${{ github.event.head_commit.committer.name }}" 176 | git config user.email "${{ github.event.head_commit.committer.email }}" 177 | git pull origin ${{github.ref}} 178 | - name: Build and test with Java 7 target 179 | if: ${{ fromJSON(matrix.java) <= 19 }} 180 | run: mvn -B clean test -DskipTests=false --file ./java/pom.xml 181 | - name: Build and test with Java 8 target 182 | if: ${{ fromJSON(matrix.java) > 19}} 183 | run: mvn -B clean test -Dproject_jdk_version=8 -DskipTests=false --file ./java/pom.xml 184 | 185 | 186 | #To ensure compatibility with the Java 7 version the build must never be run with a JDK version higher than 19 187 | release: 188 | needs: [build-and-test-with-zulu-JDK, build-and-test-with-semeru-JDK, build-and-test-with-temurin-JDK] 189 | if: ${{ fromJSON(vars.MANUAL_RELEASE_ENABLED) }} 190 | name: Release if requested 191 | runs-on: ubuntu-latest 192 | steps: 193 | - uses: actions/checkout@v3 194 | - name: Set up JDK 19 195 | uses: actions/setup-java@v3 196 | with: 197 | java-version: 19 198 | distribution: 'zulu' 199 | server-id: ossrh 200 | server-username: MAVEN_USERNAME 201 | server-password: MAVEN_PASSWORD 202 | - name: Publish to the Maven central repository 203 | run: | 204 | export GPG_TTY=$(tty) 205 | echo "${{ secrets.gpg_private_key }}" | gpg --batch --import 206 | git config user.name "${GITHUB_ACTOR}" 207 | git config user.email "info@burningwave.org" 208 | git pull origin ${{github.ref}} 209 | mv ./java/pom.xml ./java/temp-pom.xml 210 | mv ./java/sa-pom.xml ./java/pom.xml 211 | mv ./java/temp-pom.xml ./java/sa-pom.xml 212 | git commit -am "Swithcing pom for releasing" 213 | git push 214 | mvn -B release:prepare release:perform -DskipTests=true -Dgpg.passphrase=${{ secrets.gpg_passphrase }} -Dgpg.keyname=${{ secrets.gpg_key_id }} -Drepository.url=https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git --file ./java/pom.xml 215 | mv ./java/pom.xml ./java/temp-pom.xml 216 | mv ./java/sa-pom.xml ./java/pom.xml 217 | mv ./java/temp-pom.xml ./java/sa-pom.xml 218 | newVersion=$(sed -n -r 's%.*[[:space:]]*(.*-SNAPSHOT).*%\1%p' ./java/sa-pom.xml) 219 | sed -r -i "s%[[:space:]]*(.*-SNAPSHOT)%${newVersion}%" ./java/pom.xml 220 | git commit -am "Prepare for next development iteration" 221 | git push 222 | env: 223 | MAVEN_USERNAME: ${{ secrets.nexus_username }} 224 | MAVEN_PASSWORD: ${{ secrets.nexus_password }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Log file 2 | *.log 3 | 4 | # BlueJ files 5 | *.ctxt 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | *.jar 12 | *.war 13 | *.nar 14 | *.ear 15 | *.tar.gz 16 | *.rar 17 | 18 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 19 | hs_err_pid* 20 | 21 | /.project 22 | /.settings 23 | /.classpath 24 | /target/ 25 | 26 | /java/generate-header.cmd 27 | /java/.project 28 | /java/.settings 29 | /java/.classpath 30 | /java/target/ 31 | 32 | /java-hook/.project 33 | /java-hook/.settings 34 | /java-hook/.classpath 35 | /java-hook/target/ 36 | 37 | /native/.cproject 38 | /native/.project 39 | /native/.settings 40 | /native/.classpath 41 | /native/target/ 42 | /native/Debug/ 43 | /native/Release/ 44 | *.bwc 45 | 46 | .vscode 47 | .idea 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Roberto Gentili 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Burningwave JVM Driver [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=%40burningwave_org%20JVM%20driver%2C%20a%20%23Java%20driver%20to%20allow%20deep%20interaction%20with%20the%20JVM%20without%20any%20restrictions&url=https://burningwave.github.io/jvm-driver/) 2 | 3 | 4 | Burningwave-logo.png 5 | 6 | 7 | [![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/org.burningwave/jvm-driver/8)](https://maven-badges.herokuapp.com/maven-central/org.burningwave/jvm-driver/) 8 | [![GitHub](https://img.shields.io/github/license/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/blob/main/LICENSE) 9 | 10 | [![Platforms](https://img.shields.io/badge/platforms-Windows%2C%20Mac%20OS%2C%20Linux-orange)](https://github.com/burningwave/jvm-driver/actions/runs/14538126883) 11 | 12 | [![Supported JVM](https://img.shields.io/badge/supported%20JVM-7%2C%208%2C%209+%20(24)-blueviolet)](https://github.com/burningwave/jvm-driver/actions/runs/14538126883) 13 | 14 | [![GitHub open issues](https://img.shields.io/github/issues/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/issues) 15 | [![GitHub closed issues](https://img.shields.io/github/issues-closed/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/issues?q=is%3Aissue+is%3Aclosed) 16 | 17 | [![Artifact downloads](https://www.burningwave.org/generators/generate-burningwave-artifact-downloads-badge.php?artifactId=jvm-driver)](https://www.burningwave.org/artifact-downloads/?show-overall-trend-chart=false&artifactId=jvm-driver&startDate=2021-08) 18 | [![Repository dependents](https://badgen.net/github/dependents-repo/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/network/dependents) 19 | [![HitCount](https://www.burningwave.org/generators/generate-visited-pages-badge.php)](https://www.burningwave.org#bw-counters) 20 | 21 | A driver derived from [**ToolFactory JVM Driver**](https://toolfactory.github.io/jvm-driver/) with a fully extensible architecture and with a custom and [**extremely optimized JNI engine**](https://github.com/burningwave/jvm-driver/issues/3#issuecomment-1149840706) to allow deep interaction with the JVM **without any restrictions**. 22 | 23 |
24 | 25 | To include Burningwave JVM Driver in your projects simply use with **Apache Maven**: 26 | ```xml 27 | 28 | org.burningwave 29 | jvm-driver 30 | 8.19.1 31 | 32 | ``` 33 | ### Requiring the Burningwave JVM Driver module 34 | 35 | To use Burningwave JMV Driver as a Java module, add the following to your `module-info.java`: 36 | 37 | ```java 38 | //Mandatory if you use the default, dynamic or hybrid driver 39 | requires jdk.unsupported; 40 | 41 | requires org.burningwave.jvm; 42 | ``` 43 | 44 |
45 | 46 | ## Overview 47 | 48 | There are four kinds of driver: 49 | 50 | * the **default driver** completely based on Java api 51 | * the **dynamic driver** that extends the default driver and uses a JNI function only if a Java based function offered by the default driver cannot be initialized 52 | * the **hybrid driver** that extends the default driver and uses some JNI functions only when run on JVM 17 and later 53 | * the **native driver** that extends the hybrid driver and uses JNI functions more consistently regardless of the Java version it is running on 54 | 55 | All JNI methods used by the dynamic, hybrid and native driver are supplied by a **custom and highly optimized JNI engine written in C++** that works on the following system configurations: 56 | * Windows x86/x64 57 | * Linux x86/x64 58 | * MacOs x64 59 | * aarch64 (**needs testing**) 60 | 61 |
62 | 63 | ## Usage 64 | 65 | To create a driver instance you should use this code: 66 | ```java 67 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.getNew(); 68 | ``` 69 | 70 | The driver type returned by the method `io.github.toolfactory.jvm.Driver.Factory.getNew()` is **the first driver that can be initialized among the default, hybrid and native drivers respectively**. 71 | 72 | If you need to create a specific driver type you should use: 73 | 74 | * this code to create a default driver instance: 75 | 76 | ```java 77 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewDefault(); 78 | ``` 79 | 80 | * this code to create a dynamic driver instance: 81 | 82 | ```java 83 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewDynamic(); 84 | ``` 85 | 86 | * this code to create an hybrid driver instance: 87 | 88 | ```java 89 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewHybrid(); 90 | ``` 91 | 92 | * this code to create a native driver instance: 93 | 94 | ```java 95 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewNative(); 96 | ``` 97 | 98 |
99 | 100 | Each functionality offered by the driver is **initialized in deferred way** at the first call if the driver is not obtained through the method `io.github.toolfactory.jvm.Driver.getNew()`. However, it is possible to initialize all of the functionalities at once by calling the method `Driver.init()`. 101 | 102 | The methods exposed by the Driver interface are the following: 103 | ```java 104 | public D init(); 105 | 106 | public T allocateInstance(Class cls); 107 | 108 | // Return a ClassLoaderDelegate or the input itself if the input is a 109 | // BuiltinClassLoader or null if the JVM version is less than 9 110 | public ClassLoader convertToBuiltinClassLoader(ClassLoader classLoader); 111 | 112 | public Class defineHookClass(Class clientClass, byte[] byteCode); 113 | 114 | public Class getBuiltinClassLoaderClass(); 115 | 116 | public Class getClassLoaderDelegateClass(); 117 | 118 | public Class getClassByName(String className, Boolean initialize, ClassLoader classLoader, Class caller); 119 | 120 | public MethodHandles.Lookup getConsulter(Class cls); 121 | 122 | public Constructor[] getDeclaredConstructors(Class cls); 123 | 124 | public Field[] getDeclaredFields(Class cls); 125 | 126 | public Method[] getDeclaredMethods(Class cls); 127 | 128 | public T getFieldValue(Object target, Field field); 129 | 130 | public Package getPackage(ClassLoader classLoader, String packageName); 131 | 132 | public Collection getResources(String resourceRelativePath, boolean findFirst, ClassLoader... classLoaders); 133 | 134 | public Collection getResources(String resourceRelativePath, boolean findFirst, Collection classLoaders); 135 | 136 | public T invoke(Object target, Method method, Object[] params); 137 | 138 | public boolean isBuiltinClassLoader(ClassLoader classLoader); 139 | 140 | public boolean isClassLoaderDelegate(ClassLoader classLoader); 141 | 142 | public T newInstance(Constructor ctor, Object[] params); 143 | 144 | public CleanableSupplier>> getLoadedClassesRetriever(ClassLoader classLoader); 145 | 146 | public Map retrieveLoadedPackages(ClassLoader classLoader); 147 | 148 | public void setAccessible(AccessibleObject object, boolean flag); 149 | 150 | public void setFieldValue(Object target, Field field, Object value); 151 | 152 | public void stop(Thread thread); 153 | 154 | public T throwException(String message, Object... placeHolderReplacements); 155 | 156 | public T throwException(Throwable exception); 157 | ``` 158 | 159 |
160 | 161 | ## Compilation requirements 162 | 163 | **A JDK version 9 or higher and a GCC compiler are required to compile the project**. On Windows you can find compiler and GDB debugger from [**MinGW-W64 project**](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-win32/seh/). 164 | 165 |
166 | 167 | ## Contributing 168 | The [native module](https://github.com/burningwave/jvm-driver/tree/main/native) is currently compiled for Linux x86/x64, Windows x86/x64, and Mac OS X x64: **feel free to contribute native code builds for other platforms or architectures**. Once the native code is compiled you need to add a few lines of code in the [native library loader](https://github.com/burningwave/jvm-driver/blob/main/java/src/main/java/org/burningwave/jvm/util/Libraries.java). 169 | 170 |
171 | 172 | # Ask for assistance 173 | **For assistance you can**: 174 | * [open a discussion](https://github.com/burningwave/jvm-driver/discussions) here on GitHub 175 | * [report a bug](https://github.com/burningwave/jvm-driver/issues) here on GitHub 176 | * ask on [Stack Overflow](https://stackoverflow.com/search?q=burningwave) 177 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | title: Burningwave JVM driver 3 | google_analytics: UA-154852845-4 4 | show_downloads: false -------------------------------------------------------------------------------- /docs/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% if site.google_analytics %} 6 | 7 | 13 | {% endif %} 14 | 15 | 16 | {% seo %} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 37 | 38 |
39 | {{ content }} 40 | 41 | 47 |
48 | 49 | 50 | -------------------------------------------------------------------------------- /docs/assets/css/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import "{{ site.theme }}"; 5 | .page-header { 6 | background-image: linear-gradient(120deg, #e54d1d, #f7bc12); 7 | } 8 | 9 | h1.project-name { 10 | font-family: 'Aldo Pro Book'; 11 | font-size: 4.25rem; 12 | font-style: italic; 13 | line-height: 1.00em; 14 | } 15 | 16 | .main-content { 17 | h1 { 18 | color: #e54d1d; 19 | } 20 | h2 { 21 | color: #e54d1d; 22 | } 23 | h3 { 24 | color: #e54d1d; 25 | } 26 | } 27 | 28 | @font-face { 29 | font-family: 'Aldo Pro Hairline'; 30 | src: local('Aldo Pro Hairline'), local('Aldo-Pro-Hairline'), 31 | url('./../fonts/AldoPro-Hairline.woff2') format('woff2'), 32 | url('./../fonts/AldoPro-Hairline.woff') format('woff'), 33 | url('./../fonts/AldoPro-Hairline.ttf') format('truetype'); 34 | font-weight: 100; 35 | font-style: normal; 36 | } 37 | 38 | @font-face { 39 | font-family: 'Aldo Pro Light'; 40 | src: local('Aldo Pro Light'), local('Aldo-Pro-Light'), 41 | url('./../fonts/AldoPro-Light.woff2') format('woff2'), 42 | url('./../fonts/AldoPro-Light.woff') format('woff'), 43 | url('./../fonts/AldoPro-Light.ttf') format('truetype'); 44 | font-weight: 300; 45 | font-style: normal; 46 | } 47 | 48 | @font-face { 49 | font-family: 'Aldo Pro Book'; 50 | src: local('Aldo Pro Book'), local('Aldo-Pro-Book'), 51 | url('./../fonts/AldoPro-Book.woff2') format('woff2'), 52 | url('./../fonts/AldoPro-Book.woff') format('woff'), 53 | url('./../fonts/AldoPro-Book.ttf') format('truetype'); 54 | font-weight: normal; 55 | font-style: normal; 56 | } 57 | 58 | @font-face { 59 | font-family: 'Aldo Pro Regular'; 60 | src: local('Aldo Pro Regular'), local('Aldo-Pro-Regular'), 61 | url('./../fonts/AldoPro-Regular.woff2') format('woff2'), 62 | url('./../fonts/AldoPro-Regular.woff') format('woff'), 63 | url('./../fonts/AldoPro-Regular.ttf') format('truetype'); 64 | font-weight: 400; 65 | font-style: normal; 66 | } 67 | 68 | @font-face { 69 | font-family: 'Aldo Pro Medium'; 70 | src: local('Aldo Pro Medium'), local('Aldo-Pro-Medium'), 71 | url('./../fonts/AldoPro-Medium.woff2') format('woff2'), 72 | url('./../fonts/AldoPro-Medium.woff') format('woff'), 73 | url('./../fonts/AldoPro-Medium.ttf') format('truetype'); 74 | font-weight: 500; 75 | font-style: normal; 76 | } 77 | 78 | @font-face { 79 | font-family: 'Aldo Pro Bold'; 80 | src: local('Aldo Pro Bold'), local('Aldo-Pro-Bold'), 81 | url('./../fonts/AldoPro-Bold.woff2') format('woff2'), 82 | url('./../fonts/AldoPro-Bold.woff') format('woff'), 83 | url('./../fonts/AldoPro-Bold.ttf') format('truetype'); 84 | font-weight: 700; 85 | font-style: normal; 86 | } 87 | 88 | @font-face { 89 | font-family: 'Aldo Pro Black'; 90 | src: local('Aldo Pro Black'), local('Aldo-Pro-Black'), 91 | url('./../fonts/AldoPro-Black.woff2') format('woff2'), 92 | url('./../fonts/AldoPro-Black.woff') format('woff'), 93 | url('./../fonts/AldoPro-Black.ttf') format('truetype'); 94 | font-weight: 900; 95 | font-style: normal; 96 | } 97 | -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Black.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Black.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Black.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Black.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Black.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Bold.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Bold.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Bold.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Book.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Book.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Book.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Book.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Book.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Book.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Hairline.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Hairline.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Hairline.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Hairline.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Hairline.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Hairline.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Light.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Light.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Light.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Medium.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Medium.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Medium.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Regular.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Regular.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Regular.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Thin.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Thin.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Thin.woff -------------------------------------------------------------------------------- /docs/assets/fonts/AldoPro-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/docs/assets/fonts/AldoPro-Thin.woff2 -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Burningwave JVM Driver [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=%40burningwave_org%20JVM%20driver%2C%20a%20%23Java%20driver%20to%20allow%20deep%20interaction%20with%20the%20JVM%20without%20any%20restrictions&url=https://burningwave.github.io/jvm-driver/) 2 | 3 | 4 | Burningwave-logo.png 5 | 6 | 7 | [![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/org.burningwave/jvm-driver/8)](https://maven-badges.herokuapp.com/maven-central/org.burningwave/jvm-driver/) 8 | [![GitHub](https://img.shields.io/github/license/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/blob/main/LICENSE) 9 | 10 | [![Platforms](https://img.shields.io/badge/platforms-Windows%2C%20Mac%20OS%2C%20Linux-orange)](https://github.com/burningwave/jvm-driver/actions/runs/14538126883) 11 | 12 | [![Supported JVM](https://img.shields.io/badge/supported%20JVM-7%2C%208%2C%209+%20(24)-blueviolet)](https://github.com/burningwave/jvm-driver/actions/runs/14538126883) 13 | 14 | [![GitHub open issues](https://img.shields.io/github/issues/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/issues) 15 | [![GitHub closed issues](https://img.shields.io/github/issues-closed/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/issues?q=is%3Aissue+is%3Aclosed) 16 | 17 | [![Artifact downloads](https://www.burningwave.org/generators/generate-burningwave-artifact-downloads-badge.php?artifactId=jvm-driver)](https://www.burningwave.org/artifact-downloads/?show-overall-trend-chart=false&artifactId=jvm-driver&startDate=2021-08) 18 | [![Repository dependents](https://badgen.net/github/dependents-repo/burningwave/jvm-driver)](https://github.com/burningwave/jvm-driver/network/dependents) 19 | [![HitCount](https://www.burningwave.org/generators/generate-visited-pages-badge.php)](https://www.burningwave.org#bw-counters) 20 | 21 | A driver derived from [**ToolFactory JVM Driver**](https://toolfactory.github.io/jvm-driver/) with a fully extensible architecture and with a custom and [**extremely optimized JNI engine**](https://github.com/burningwave/jvm-driver/issues/3#issuecomment-1149840706) to allow deep interaction with the JVM **without any restrictions**. 22 | 23 |
24 | 25 | To include Burningwave JVM Driver in your projects simply use with **Apache Maven**: 26 | ```xml 27 | 28 | org.burningwave 29 | jvm-driver 30 | 8.19.1 31 | 32 | ``` 33 | ### Requiring the Burningwave JVM Driver module 34 | 35 | To use Burningwave JMV Driver as a Java module, add the following to your `module-info.java`: 36 | 37 | ```java 38 | //Mandatory if you use the default, dynamic or hybrid driver 39 | requires jdk.unsupported; 40 | 41 | requires org.burningwave.jvm; 42 | ``` 43 | 44 |
45 | 46 | ## Overview 47 | 48 | There are four kinds of driver: 49 | 50 | * the **default driver** completely based on Java api 51 | * the **dynamic driver** that extends the default driver and uses a JNI function only if a Java based function offered by the default driver cannot be initialized 52 | * the **hybrid driver** that extends the default driver and uses some JNI functions only when run on JVM 17 and later 53 | * the **native driver** that extends the hybrid driver and uses JNI functions more consistently regardless of the Java version it is running on 54 | 55 | All JNI methods used by the dynamic, hybrid and native driver are supplied by a **custom and highly optimized JNI engine written in C++** that works on the following system configurations: 56 | * Windows x86/x64 57 | * Linux x86/x64 58 | * MacOs x64 59 | * aarch64 (**needs testing**) 60 | 61 |
62 | 63 | ## Usage 64 | 65 | To create a driver instance you should use this code: 66 | ```java 67 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.getNew(); 68 | ``` 69 | 70 | The driver type returned by the method `io.github.toolfactory.jvm.Driver.Factory.getNew()` is **the first driver that can be initialized among the default, hybrid and native drivers respectively**. 71 | 72 | If you need to create a specific driver type you should use: 73 | 74 | * this code to create a default driver instance: 75 | 76 | ```java 77 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewDefault(); 78 | ``` 79 | 80 | * this code to create a dynamic driver instance: 81 | 82 | ```java 83 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewDynamic(); 84 | ``` 85 | 86 | * this code to create an hybrid driver instance: 87 | 88 | ```java 89 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewHybrid(); 90 | ``` 91 | 92 | * this code to create a native driver instance: 93 | 94 | ```java 95 | io.github.toolfactory.jvm.Driver driver = io.github.toolfactory.jvm.Driver.Factory.getNewNative(); 96 | ``` 97 | 98 |
99 | 100 | Each functionality offered by the driver is **initialized in deferred way** at the first call if the driver is not obtained through the method `io.github.toolfactory.jvm.Driver.getNew()`. However, it is possible to initialize all of the functionalities at once by calling the method `Driver.init()`. 101 | 102 | The methods exposed by the Driver interface are the following: 103 | ```java 104 | public D init(); 105 | 106 | public T allocateInstance(Class cls); 107 | 108 | // Return a ClassLoaderDelegate or the input itself if the input is a 109 | // BuiltinClassLoader or null if the JVM version is less than 9 110 | public ClassLoader convertToBuiltinClassLoader(ClassLoader classLoader); 111 | 112 | public Class defineHookClass(Class clientClass, byte[] byteCode); 113 | 114 | public Class getBuiltinClassLoaderClass(); 115 | 116 | public Class getClassLoaderDelegateClass(); 117 | 118 | public Class getClassByName(String className, Boolean initialize, ClassLoader classLoader, Class caller); 119 | 120 | public MethodHandles.Lookup getConsulter(Class cls); 121 | 122 | public Constructor[] getDeclaredConstructors(Class cls); 123 | 124 | public Field[] getDeclaredFields(Class cls); 125 | 126 | public Method[] getDeclaredMethods(Class cls); 127 | 128 | public T getFieldValue(Object target, Field field); 129 | 130 | public Package getPackage(ClassLoader classLoader, String packageName); 131 | 132 | public Collection getResources(String resourceRelativePath, boolean findFirst, ClassLoader... classLoaders); 133 | 134 | public Collection getResources(String resourceRelativePath, boolean findFirst, Collection classLoaders); 135 | 136 | public T invoke(Object target, Method method, Object[] params); 137 | 138 | public boolean isBuiltinClassLoader(ClassLoader classLoader); 139 | 140 | public boolean isClassLoaderDelegate(ClassLoader classLoader); 141 | 142 | public T newInstance(Constructor ctor, Object[] params); 143 | 144 | public CleanableSupplier>> getLoadedClassesRetriever(ClassLoader classLoader); 145 | 146 | public Map retrieveLoadedPackages(ClassLoader classLoader); 147 | 148 | public void setAccessible(AccessibleObject object, boolean flag); 149 | 150 | public void setFieldValue(Object target, Field field, Object value); 151 | 152 | public void stop(Thread thread); 153 | 154 | public T throwException(String message, Object... placeHolderReplacements); 155 | 156 | public T throwException(Throwable exception); 157 | ``` 158 | 159 |
160 | 161 | ## Compilation requirements 162 | 163 | **A JDK version 9 or higher and a GCC compiler are required to compile the project**. On Windows you can find compiler and GDB debugger from [**MinGW-W64 project**](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-win32/seh/). 164 | 165 |
166 | 167 | ## Contributing 168 | The [native module](https://github.com/burningwave/jvm-driver/tree/main/native) is currently compiled for Linux x86/x64, Windows x86/x64, and Mac OS X x64: **feel free to contribute native code builds for other platforms or architectures**. Once the native code is compiled you need to add a few lines of code in the [native library loader](https://github.com/burningwave/jvm-driver/blob/main/java/src/main/java/org/burningwave/jvm/util/Libraries.java). 169 | 170 |
171 | 172 | # Ask for assistance 173 | **For assistance you can**: 174 | * [open a discussion](https://github.com/burningwave/jvm-driver/discussions) here on GitHub 175 | * [report a bug](https://github.com/burningwave/jvm-driver/issues) here on GitHub 176 | * ask on [Stack Overflow](https://stackoverflow.com/search?q=burningwave) 177 | -------------------------------------------------------------------------------- /java/pom.xml: -------------------------------------------------------------------------------- 1 | 31 | 34 | 4.0.0 35 | 36 | 37 | org.burningwave 38 | jvm-driver-parent 39 | ${revision} 40 | 41 | 42 | jvm-driver 43 | 8.19.2-SNAPSHOT 44 | 45 | jar 46 | 47 | Burningwave JVM Driver 48 | 49 | A driver derived from ToolFactory JVM Driver to allow deep interaction with the JVM without any restrictions 50 | 51 | https://burningwave.github.io/jvm-driver/ 52 | 53 | 54 | 55 | MIT License 56 | https://github.com/burningwave/jvm-driver/blob/master/LICENSE 57 | repo 58 | 59 | 60 | 61 | 62 | Burningwave 63 | https://www.burningwave.org/ 64 | 65 | 66 | 67 | 68 | Roberto Gentili 69 | roberto.gentili 70 | info@burningwave.org 71 | Burningwave 72 | https://www.burningwave.org/ 73 | 74 | Administrator 75 | Developer 76 | 77 | 78 | 79 | Alessio Perrotta 80 | info@burningwave.org 81 | Burningwave 82 | https://www.burningwave.org/ 83 | 84 | External relationship manager 85 | Developer 86 | 87 | 88 | 89 | 90 | 91 | UTF-8 92 | UTF-8 93 | 7 94 | bin/javadoc 95 | true 96 | AllTestsSuite 97 | **/${project.test.testSuite}.java 98 | **/*Test.java 99 | 100 | 5.10.0 101 | 1.10.0 102 | 9.8.0 103 | 3.1.0 104 | 5.1.9 105 | 3.11.0 106 | 3.3.0 107 | 3.2.0 108 | 3.0.1 109 | 3.2.1 110 | 111 | 112 | 113 | 114 | 115 | io.github.toolfactory 116 | jvm-driver 117 | ${jvm-driver.version} 118 | 119 | 120 | io.github.toolfactory 121 | narcissus 122 | 123 | 124 | 125 | 126 | 127 | org.junit.jupiter 128 | junit-jupiter-engine 129 | ${junit-jupiter.version} 130 | test 131 | 132 | 133 | 134 | org.junit.platform 135 | junit-platform-engine 136 | ${junit.version} 137 | test 138 | 139 | 140 | 141 | org.junit.platform 142 | junit-platform-commons 143 | ${junit.version} 144 | test 145 | 146 | 147 | 148 | org.junit.platform 149 | junit-platform-runner 150 | ${junit.version} 151 | test 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | ${project.basedir}/../ 160 | 161 | **LICENSE 162 | 163 | META-INF 164 | 165 | 166 | ${project.basedir}/src/main/resources 167 | 168 | ** 169 | 170 | 171 | 172 | ${project.basedir}/../native/src/main/c-c++ 173 | 174 | ** 175 | 176 | 177 | 178 | 179 | 180 | ${project.basedir}/src/test/resources 181 | 182 | 183 | 184 | 185 | maven-antrun-plugin 186 | ${maven-antrun-plugin.version} 187 | 188 | 189 | 190 | run 191 | 192 | 193 | compile 194 | 195 | 196 | 197 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | add-module-info-to-jar 206 | package 207 | 208 | run 209 | 210 | 211 | 212 | 214 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | org.apache.maven.plugins 225 | maven-compiler-plugin 226 | ${maven-compiler-plugin.version} 227 | 228 | 229 | default-compile 230 | 231 | 232 | 9 233 | 234 | 235 | 236 | 237 | default-testCompile 238 | 239 | 240 | module-info.java 241 | 242 | ${project_jdk_version} 243 | true 244 | 245 | 246 | 247 | base-compile 248 | 249 | compile 250 | 251 | 252 | 253 | 254 | module-info.java 255 | 256 | ${project_jdk_version} 257 | ${project_jdk_version} 258 | 259 | 260 | 261 | 262 | 263 | org.apache.maven.plugins 264 | maven-surefire-plugin 265 | ${maven-surefire-plugin.version} 266 | 267 | ${skipTests} 268 | 269 | ${project.test.excludes} 270 | 271 | 272 | ${project.test.includes} 273 | 274 | false 275 | 276 | 277 | 278 | org.apache.felix 279 | maven-bundle-plugin 280 | ${maven-bundle-plugin.version} 281 | true 282 | 283 | 284 | generate-manifest 285 | process-classes 286 | 287 | manifest 288 | 289 | 290 | 291 | 292 | ${project.build.outputDirectory}/META-INF/ 293 | true 294 | 295 | Utilities 296 | ${organization.name} 297 | https://github.com/burningwave/jvm-driver/blob/master/LICENSE 298 | 2 299 | JVM Driver 300 | ${project.groupId}.${project.artifactId} 301 | ${organization.name} 302 | ${project.description} 303 | ${project.version} 304 | osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))" 305 | io.github.toolfactory.jvm;version="${jvm-driver.version}",io.github.toolfactory.jvm.function.catalog;version="${jvm-driver.version}",io.github.toolfactory.jvm.function.template;version="${jvm-driver.version}",io.github.toolfactory.jvm.util;version="${jvm-driver.version}" 306 | true 307 | <_dsannotations>* 308 | <_metatypeannotations>* 309 | 310 | 311 | 312 | 313 | maven-jar-plugin 314 | ${maven-jar-plugin.version} 315 | 316 | 317 | module-info.class 318 | **/*.c 319 | **/*.cpp 320 | **/*.h 321 | META-INF/maven/ 322 | 323 | 324 | false 325 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF 326 | 327 | 328 | 329 | 330 | org.apache.maven.plugins 331 | maven-javadoc-plugin 332 | ${maven-javadoc-plugin.version} 333 | 334 | ${java.home}/${javadocExecutable.relativePath} 335 | UTF-8 336 | ${project_jdk_version} 337 | 338 | 339 | 340 | attach-javadoc 341 | 342 | jar 343 | 344 | 345 | 346 | 347 | 348 | org.apache.maven.plugins 349 | maven-source-plugin 350 | ${maven-source-plugin.version} 351 | 352 | 353 | attach-sources 354 | 355 | jar 356 | 357 | 358 | 359 | 360 | 361 | 362 | -------------------------------------------------------------------------------- /java/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | module org.burningwave.jvm { 30 | 31 | requires io.github.toolfactory.jvm; 32 | 33 | exports org.burningwave.jvm; 34 | exports org.burningwave.jvm.function.catalog; 35 | exports org.burningwave.jvm.util; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/DynamicDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * -- 7 | * 8 | * The MIT License (MIT) 9 | * 10 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 11 | * 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 13 | * documentation files (the "Software"), to deal in the Software without restriction, including without 14 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 16 | * conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all copies or substantial 19 | * portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 22 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 23 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 24 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 25 | * OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | package org.burningwave.jvm; 28 | 29 | 30 | import java.util.Map; 31 | 32 | import org.burningwave.jvm.function.catalog.AllocateInstanceFunction; 33 | import org.burningwave.jvm.function.catalog.ConsulterSupplier; 34 | import org.burningwave.jvm.function.catalog.GetFieldValueFunction; 35 | import org.burningwave.jvm.function.catalog.GetLoadedClassesRetrieverFunction; 36 | import org.burningwave.jvm.function.catalog.GetLoadedPackagesFunction; 37 | import org.burningwave.jvm.function.catalog.SetAccessibleFunction; 38 | import org.burningwave.jvm.function.catalog.SetFieldValueFunction; 39 | 40 | import io.github.toolfactory.jvm.DefaultDriver; 41 | import io.github.toolfactory.jvm.util.ObjectProvider; 42 | import io.github.toolfactory.jvm.util.ObjectProvider.BuildingException; 43 | 44 | 45 | public class DynamicDriver extends DefaultDriver { 46 | 47 | @Override 48 | protected Map functionsToMap() { 49 | Map context = super.functionsToMap(); 50 | ObjectProvider.setExceptionHandler( 51 | context, 52 | new ObjectProvider.ExceptionHandler() { 53 | @Override 54 | public T handle(ObjectProvider objectProvider, Class clazz, Map context, 55 | BuildingException exc) { 56 | if (clazz.equals(ConsulterSupplier.class)) { 57 | return objectProvider.getOrBuildObject(ConsulterSupplier.Native.class, context); 58 | } 59 | if (clazz.equals(SetFieldValueFunction.class)) { 60 | return objectProvider.getOrBuildObject(SetFieldValueFunction.Native.class, context); 61 | } 62 | if (clazz.equals(AllocateInstanceFunction.class)) { 63 | return objectProvider.getOrBuildObject(AllocateInstanceFunction.Native.class, context); 64 | } 65 | if (clazz.equals(SetAccessibleFunction.class)) { 66 | return objectProvider.getOrBuildObject(SetAccessibleFunction.Native.class, context); 67 | } 68 | if (clazz.equals(GetFieldValueFunction.class)) { 69 | return objectProvider.getOrBuildObject(GetFieldValueFunction.Native.class, context); 70 | } 71 | if (clazz.equals(GetLoadedClassesRetrieverFunction.class)) { 72 | return objectProvider.getOrBuildObject(GetLoadedClassesRetrieverFunction.Native.class, context); 73 | } 74 | if (clazz.equals(GetLoadedPackagesFunction.class)) { 75 | return objectProvider.getOrBuildObject(GetLoadedPackagesFunction.Native.class, context); 76 | } 77 | throw exc; 78 | } 79 | } 80 | ); 81 | return context; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/HybridDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm; 32 | 33 | 34 | import org.burningwave.jvm.function.catalog.ConsulterSupplier; 35 | import org.burningwave.jvm.function.catalog.ConsulterSupplyFunction; 36 | 37 | 38 | 39 | 40 | public class HybridDriver extends io.github.toolfactory.jvm.HybridDriver { 41 | 42 | @Override 43 | protected Class getConsulterSupplierFunctionClass() { 44 | return ConsulterSupplier.Hybrid.class; 45 | } 46 | 47 | @Override 48 | protected Class getConsulterSupplyFunctionClass() { 49 | return ConsulterSupplyFunction.Hybrid.class; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/NativeDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm; 32 | 33 | 34 | import org.burningwave.jvm.function.catalog.AllocateInstanceFunction; 35 | import org.burningwave.jvm.function.catalog.ConsulterSupplier; 36 | import org.burningwave.jvm.function.catalog.ConsulterSupplyFunction; 37 | import org.burningwave.jvm.function.catalog.GetFieldValueFunction; 38 | import org.burningwave.jvm.function.catalog.GetLoadedClassesRetrieverFunction; 39 | import org.burningwave.jvm.function.catalog.GetLoadedPackagesFunction; 40 | import org.burningwave.jvm.function.catalog.SetAccessibleFunction; 41 | import org.burningwave.jvm.function.catalog.SetFieldValueFunction; 42 | 43 | 44 | public class NativeDriver extends io.github.toolfactory.jvm.NativeDriver { 45 | 46 | @Override 47 | protected Class getConsulterSupplierFunctionClass() { 48 | return ConsulterSupplier.Native.class; 49 | } 50 | 51 | @Override 52 | protected Class getConsulterSupplyFunctionClass() { 53 | return ConsulterSupplyFunction.Native.class; 54 | } 55 | 56 | 57 | @Override 58 | protected Class getGetLoadedPackagesFunctionClass() { 59 | return GetLoadedPackagesFunction.Native.class; 60 | } 61 | 62 | @Override 63 | protected Class getGetLoadedClassesRetrieverFunctionClass() { 64 | return GetLoadedClassesRetrieverFunction.Native.class; 65 | } 66 | 67 | 68 | @Override 69 | protected Class getSetFieldValueFunctionClass() { 70 | return SetFieldValueFunction.Native.class; 71 | } 72 | 73 | 74 | @Override 75 | protected Class getGetFieldValueFunctionClass() { 76 | return GetFieldValueFunction.Native.class; 77 | } 78 | 79 | 80 | @Override 81 | protected Class getAllocateInstanceFunctionClass() { 82 | return AllocateInstanceFunction.Native.class; 83 | } 84 | 85 | 86 | @Override 87 | protected Class getSetAccessibleFunctionClass() { 88 | return SetAccessibleFunction.Native.class; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/AllocateInstanceFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.util.Map; 35 | 36 | 37 | public interface AllocateInstanceFunction extends io.github.toolfactory.jvm.function.catalog.AllocateInstanceFunction { 38 | 39 | public static interface Native extends AllocateInstanceFunction { 40 | 41 | public static class ForJava7 implements Native { 42 | org.burningwave.jvm.NativeExecutor nativeExecutor; 43 | 44 | public ForJava7(Map context) { 45 | nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 46 | } 47 | 48 | @Override 49 | public Object apply(Class cls) { 50 | return nativeExecutor.allocateInstance(cls); 51 | } 52 | 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/ConsulterSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.lang.invoke.MethodHandles; 35 | import java.lang.reflect.Field; 36 | import java.util.Map; 37 | 38 | 39 | public interface ConsulterSupplier extends io.github.toolfactory.jvm.function.catalog.ConsulterSupplier { 40 | 41 | public static interface Native extends ConsulterSupplier { 42 | 43 | public static class ForJava7 extends io.github.toolfactory.jvm.function.catalog.ConsulterSupplier.Abst implements Native { 44 | 45 | public ForJava7(Map context) throws NoSuchFieldException { 46 | super(context); 47 | org.burningwave.jvm.NativeExecutor nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 48 | Field allowedModesField = nativeExecutor.getDeclaredField(MethodHandles.Lookup.class, "allowedModes", "I"); 49 | nativeExecutor.setFieldValue(consulter, allowedModesField, -1); 50 | } 51 | 52 | public static class ForSemeru extends Abst implements ConsulterSupplier.Native { 53 | 54 | public ForSemeru(Map context) throws NoSuchFieldException { 55 | super(context); 56 | org.burningwave.jvm.NativeExecutor nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 57 | Field allowedModesField = nativeExecutor.getDeclaredField(MethodHandles.Lookup.class, "accessMode", "I"); 58 | nativeExecutor.setFieldValue( 59 | consulter, 60 | allowedModesField, 61 | io.github.toolfactory.jvm.function.catalog.ConsulterSupplier.ForJava7.ForSemeru.INTERNAL_PRIVILEGED 62 | ); 63 | } 64 | } 65 | } 66 | 67 | public static interface ForJava9 extends Native, ConsulterSupplier { 68 | 69 | public static class ForSemeru extends Abst implements Native.ForJava9 { 70 | 71 | public ForSemeru(Map context) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { 72 | super(context); 73 | org.burningwave.jvm.NativeExecutor nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 74 | Field allowedModesField = nativeExecutor.getDeclaredField(MethodHandles.Lookup.class, "accessMode", "I"); 75 | nativeExecutor.setFieldValue( 76 | consulter, 77 | allowedModesField, 78 | io.github.toolfactory.jvm.function.catalog.ConsulterSupplier.ForJava7.ForSemeru.INTERNAL_PRIVILEGED | 79 | io.github.toolfactory.jvm.function.catalog.ConsulterSupplier.ForJava9.ForSemeru.MODULE 80 | ); 81 | } 82 | 83 | } 84 | } 85 | 86 | public static interface ForJava14 extends Native, ConsulterSupplier { 87 | 88 | public static class ForSemeru extends ConsulterSupplier.Native.ForJava7.ForSemeru implements Native.ForJava14 { 89 | 90 | public ForSemeru(Map context) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { 91 | super(context); 92 | } 93 | } 94 | } 95 | 96 | public static interface ForJava17 extends Native, ConsulterSupplier { 97 | 98 | public static class ForSemeru extends Native.ForJava7 implements Native.ForJava17 { 99 | 100 | public ForSemeru(Map context) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { 101 | super(context); 102 | } 103 | } 104 | } 105 | 106 | } 107 | 108 | 109 | public static interface Hybrid extends ConsulterSupplier { 110 | 111 | public static class ForJava17 extends ConsulterSupplier.Native.ForJava7 implements Hybrid { 112 | 113 | public ForJava17(Map context) throws NoSuchFieldException { 114 | super(context); 115 | } 116 | 117 | public static class ForSemeru extends ConsulterSupplier.Native.ForJava17.ForSemeru implements ConsulterSupplier.Hybrid { 118 | 119 | public ForSemeru(Map context) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { 120 | super(context); 121 | } 122 | } 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/ConsulterSupplyFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * -- 7 | * 8 | * The MIT License (MIT) 9 | * 10 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 11 | * 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 13 | * documentation files (the "Software"), to deal in the Software without restriction, including without 14 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 15 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 16 | * conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all copies or substantial 19 | * portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 22 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 23 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 24 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 25 | * OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | package org.burningwave.jvm.function.catalog; 28 | 29 | 30 | import java.lang.invoke.MethodHandles; 31 | import java.util.Map; 32 | 33 | 34 | public interface ConsulterSupplyFunction extends io.github.toolfactory.jvm.function.catalog.ConsulterSupplyFunction { 35 | 36 | public static interface Native extends ConsulterSupplyFunction { 37 | 38 | public static interface ForJava17 extends Native { 39 | 40 | public static class ForSemeru extends io.github.toolfactory.jvm.function.catalog.ConsulterSupplyFunction.ForJava17.ForSemeru implements ForJava17 { 41 | public ForSemeru(Map context) throws Throwable { 42 | super(context); 43 | 44 | } 45 | 46 | @Override 47 | protected void empowerMainConsulter(MethodHandles.Lookup consulter, Map context) throws Throwable { 48 | org.burningwave.jvm.NativeExecutor nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 49 | nativeExecutor.setFieldValue( 50 | consulter, 51 | nativeExecutor.getDeclaredField(MethodHandles.Lookup.class, "allowedModes", "I"), 52 | -1 53 | ); 54 | } 55 | 56 | } 57 | 58 | } 59 | 60 | } 61 | 62 | public static interface Hybrid extends ConsulterSupplyFunction { 63 | 64 | public static interface ForJava17 extends Hybrid { 65 | 66 | public static class ForSemeru extends Native.ForJava17.ForSemeru implements Hybrid.ForJava17 { 67 | 68 | public ForSemeru(Map context) throws Throwable { 69 | super(context); 70 | } 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/GetFieldValueFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.lang.reflect.Field; 35 | import java.util.Map; 36 | 37 | 38 | public interface GetFieldValueFunction extends io.github.toolfactory.jvm.function.catalog.GetFieldValueFunction { 39 | 40 | public static interface Native extends GetFieldValueFunction { 41 | 42 | public static class ForJava7 implements Native { 43 | org.burningwave.jvm.NativeExecutor nativeExecutor; 44 | 45 | public ForJava7(Map context) { 46 | nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 47 | } 48 | 49 | @Override 50 | public Object apply(Object target, Field field) { 51 | return nativeExecutor.getFieldValue(target, field); 52 | } 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/GetLoadedClassesRetrieverFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.lang.reflect.Field; 35 | import java.util.Collection; 36 | import java.util.Hashtable; 37 | import java.util.Map; 38 | 39 | import io.github.toolfactory.jvm.function.catalog.GetDeclaredFieldFunction; 40 | import io.github.toolfactory.jvm.function.catalog.ThrowExceptionFunction; 41 | import io.github.toolfactory.jvm.util.CleanableSupplier; 42 | import io.github.toolfactory.jvm.util.ObjectProvider; 43 | 44 | 45 | @SuppressWarnings("all") 46 | public interface GetLoadedClassesRetrieverFunction extends io.github.toolfactory.jvm.function.catalog.GetLoadedClassesRetrieverFunction { 47 | 48 | public static interface Native extends GetLoadedClassesRetrieverFunction { 49 | 50 | public static class ForJava7 implements Native { 51 | protected Field classesField; 52 | protected org.burningwave.jvm.NativeExecutor nativeExecutor; 53 | 54 | public ForJava7(Map context) throws Throwable { 55 | ObjectProvider functionProvider = ObjectProvider.get(context); 56 | GetDeclaredFieldFunction getDeclaredFieldFunction = functionProvider.getOrBuildObject(GetDeclaredFieldFunction.class, context); 57 | classesField = getDeclaredFieldFunction.apply(ClassLoader.class, "classes"); 58 | nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 59 | } 60 | 61 | @Override 62 | public CleanableSupplier>> apply(final ClassLoader classLoader) { 63 | if (classLoader == null) { 64 | throw new NullPointerException("Input classLoader parameter can't be null"); 65 | } 66 | return new CleanableSupplier>>() { 67 | Collection> classes; 68 | 69 | @Override 70 | public Collection> get() { 71 | if (classes != null) { 72 | return classes; 73 | } 74 | return classes = (Collection>)nativeExecutor.getFieldValue(classLoader, classesField); 75 | } 76 | 77 | @Override 78 | public void clear() { 79 | get(); 80 | if (classes != null) { 81 | classes.clear(); 82 | } 83 | } 84 | 85 | }; 86 | } 87 | 88 | public static class ForSemeru extends GetLoadedClassesRetrieverFunction.ForJava7.ForSemeru { 89 | protected org.burningwave.jvm.NativeExecutor nativeExecutor; 90 | 91 | 92 | public ForSemeru(Map context) throws Throwable { 93 | super(context); 94 | nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 95 | } 96 | 97 | @Override 98 | protected ClassNameBasedLockSupplier buildClassNameBasedLockSupplier(final Map context) { 99 | return new ClassNameBasedLockSupplier() { 100 | protected ThrowExceptionFunction throwExceptionFunction = 101 | ObjectProvider.get(context).getOrBuildObject(ThrowExceptionFunction.class, context); 102 | 103 | @Override 104 | public Hashtable get(ClassLoader classLoader) { 105 | return (Hashtable)nativeExecutor.getFieldValue(classLoader, classNameBasedLockField); 106 | } 107 | 108 | @Override 109 | protected ClassLoader getClassLoader(Class cls) { 110 | return (ClassLoader)nativeExecutor.getFieldValue(cls, classLoaderField); 111 | } 112 | 113 | }; 114 | 115 | } 116 | 117 | } 118 | } 119 | 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/GetLoadedPackagesFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.lang.reflect.Field; 35 | import java.util.Map; 36 | 37 | import io.github.toolfactory.jvm.function.catalog.GetDeclaredFieldFunction; 38 | import io.github.toolfactory.jvm.util.ObjectProvider; 39 | 40 | 41 | @SuppressWarnings("all") 42 | public interface GetLoadedPackagesFunction extends io.github.toolfactory.jvm.function.catalog.GetLoadedPackagesFunction { 43 | 44 | public interface Native extends GetLoadedPackagesFunction { 45 | 46 | public static class ForJava7 implements Native { 47 | Field packagesField; 48 | org.burningwave.jvm.NativeExecutor nativeExecutor; 49 | 50 | public ForJava7(Map context) throws Throwable { 51 | ObjectProvider functionProvider = ObjectProvider.get(context); 52 | GetDeclaredFieldFunction getDeclaredFieldFunction = functionProvider.getOrBuildObject(GetDeclaredFieldFunction.class, context); 53 | packagesField = getDeclaredFieldFunction.apply(ClassLoader.class, "packages"); 54 | nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 55 | } 56 | 57 | @Override 58 | public Map apply(ClassLoader classLoader) { 59 | return (Map)nativeExecutor.getFieldValue(classLoader, packagesField); 60 | } 61 | } 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/SetAccessibleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.lang.reflect.AccessibleObject; 35 | import java.lang.reflect.Field; 36 | import java.util.Map; 37 | 38 | import io.github.toolfactory.jvm.function.template.ThrowingBiConsumer; 39 | 40 | 41 | public interface SetAccessibleFunction extends io.github.toolfactory.jvm.function.catalog.SetAccessibleFunction { 42 | 43 | public interface Native extends SetAccessibleFunction { 44 | 45 | public static class ForJava7 extends io.github.toolfactory.jvm.function.catalog.SetAccessibleFunction.Abst> { 46 | public ForJava7(Map context) { 47 | super(context); 48 | final org.burningwave.jvm.NativeExecutor nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 49 | final Field overrideField = nativeExecutor.getDeclaredField(AccessibleObject.class, "override", "Z"); 50 | setFunction(new ThrowingBiConsumer() { 51 | @Override 52 | public void accept(AccessibleObject accessibleObject, Boolean flag) { 53 | nativeExecutor.setFieldValue(accessibleObject, overrideField, flag); 54 | } 55 | }); 56 | 57 | 58 | } 59 | 60 | @Override 61 | public void accept(AccessibleObject accessibleObject, Boolean flag) throws Throwable { 62 | function.accept(accessibleObject, flag); 63 | } 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/function/catalog/SetFieldValueFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.function.catalog; 32 | 33 | 34 | import java.lang.reflect.Field; 35 | import java.util.Map; 36 | 37 | 38 | public interface SetFieldValueFunction extends io.github.toolfactory.jvm.function.catalog.SetFieldValueFunction { 39 | 40 | public interface Native extends SetFieldValueFunction { 41 | 42 | public static class ForJava7 extends io.github.toolfactory.jvm.function.catalog.SetFieldValueFunction.Abst implements Native { 43 | org.burningwave.jvm.NativeExecutor nativeExecutor; 44 | 45 | public ForJava7(Map context) { 46 | super(context); 47 | nativeExecutor = org.burningwave.jvm.NativeExecutor.getInstance(); 48 | } 49 | 50 | @Override 51 | public void accept(Object target, Field field, Object value) { 52 | nativeExecutor.setFieldValue(target, field, value); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/util/Files.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory Narcissus. 3 | * 4 | * Hosted at: https://github.com/toolfactory/narcissus 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.util; 32 | 33 | 34 | import java.io.File; 35 | import java.io.FileNotFoundException; 36 | import java.io.FileOutputStream; 37 | import java.io.InputStream; 38 | import java.io.OutputStream; 39 | 40 | import io.github.toolfactory.jvm.function.template.Consumer; 41 | import io.github.toolfactory.jvm.util.Strings; 42 | 43 | 44 | public class Files { 45 | 46 | 47 | public static void extractAndExecute(Class callerClass, String resourcePath, Consumer extractedFileConsumer) { 48 | 49 | try ( 50 | InputStream inputStream = callerClass.getResourceAsStream(resourcePath.startsWith("/") ? resourcePath : "/" + resourcePath); 51 | ) { 52 | if (inputStream == null) { 53 | throw new FileNotFoundException("Could not find file: " + resourcePath); 54 | } 55 | String filename = resourcePath.substring(resourcePath.lastIndexOf('/') + 1); 56 | try (TempFileHolder tempFileHandler = new TempFileHolder(filename)) { 57 | byte[] buffer = new byte[1024]; 58 | try (OutputStream os = new FileOutputStream(tempFileHandler.getFile())) { 59 | for (int readBytes; (readBytes = inputStream.read(buffer)) != -1;) { 60 | os.write(buffer, 0, readBytes); 61 | } 62 | } 63 | extractedFileConsumer.accept(tempFileHandler.getFile()); 64 | } 65 | } catch (Throwable exc) { 66 | throw new NotLoadedException(Strings.compile("Unable to load file {}", resourcePath), exc); 67 | } 68 | } 69 | 70 | public static class NotLoadedException extends RuntimeException { 71 | 72 | private static final long serialVersionUID = -461698261422622020L; 73 | 74 | public NotLoadedException(String message, Throwable cause) { 75 | super(message, cause); 76 | } 77 | 78 | public NotLoadedException(String message) { 79 | super(message); 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/util/Libraries.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory Narcissus. 3 | * 4 | * Hosted at: https://github.com/toolfactory/narcissus 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.util; 32 | 33 | 34 | import java.io.File; 35 | import java.util.Locale; 36 | 37 | import org.burningwave.jvm.NativeExecutor; 38 | 39 | import io.github.toolfactory.jvm.InfoImpl; 40 | import io.github.toolfactory.jvm.function.template.Consumer; 41 | import io.github.toolfactory.jvm.util.Strings; 42 | 43 | 44 | public class Libraries { 45 | 46 | String conventionedSuffix; 47 | String extension; 48 | String prefix; 49 | 50 | 51 | private Libraries() { 52 | io.github.toolfactory.jvm.InfoImpl jVMInfo = (InfoImpl)io.github.toolfactory.jvm.Info.Provider.getInfoInstance(); 53 | if (jVMInfo.is32Bit()) { 54 | conventionedSuffix = "x32"; 55 | } else if (jVMInfo.is64Bit()) { 56 | conventionedSuffix = "x64"; 57 | } 58 | String osArch = jVMInfo.osArch != null ? jVMInfo.osArch : "generic"; 59 | String operatingSystemName = jVMInfo.operatingSystemName != null ? jVMInfo.operatingSystemName.toLowerCase(Locale.ENGLISH) : "generic"; 60 | prefix = "lib"; 61 | if (osArch.equals("aarch64")) { 62 | conventionedSuffix = osArch; 63 | extension = "so"; 64 | } else if ((operatingSystemName.indexOf("mac") >= 0) || (operatingSystemName.indexOf("darwin") >= 0)) { 65 | extension = "dylib"; 66 | } else if (operatingSystemName.indexOf("win") >= 0) { 67 | prefix = null; 68 | extension = "dll"; 69 | } else if (operatingSystemName.indexOf("nux") >= 0) { 70 | extension = "so"; 71 | } else { 72 | throw new InitializeException( 73 | Strings.compile( 74 | "Unable to initialize {}: unsupported operating system ('{}-{}')", 75 | this, operatingSystemName, osArch 76 | ) 77 | ); 78 | } 79 | } 80 | 81 | public static Libraries getInstance() { 82 | return Holder.getWithinInstance(); 83 | } 84 | 85 | static Libraries create() { 86 | return new Libraries(); 87 | } 88 | 89 | public String loadFor(Class clazz) { 90 | String libName = clazz.getPackage().getName(); 91 | if (libName != null) { 92 | libName = libName.replace(".", "/") + "/"; 93 | } else { 94 | libName = ""; 95 | } 96 | if (prefix != null) { 97 | libName += prefix; 98 | } 99 | libName += clazz.getSimpleName() + "-" + conventionedSuffix + "." + extension; 100 | Files.extractAndExecute( 101 | NativeExecutor.class, 102 | libName, 103 | new Consumer() { 104 | @Override 105 | public void accept(File libraryFile) { 106 | System.load(libraryFile.getAbsolutePath()); 107 | } 108 | } 109 | 110 | ); 111 | return clazz.getSimpleName() + "-" + conventionedSuffix; 112 | } 113 | 114 | private static class Holder { 115 | private static final Libraries INSTANCE = Libraries.create(); 116 | 117 | private static Libraries getWithinInstance() { 118 | return INSTANCE; 119 | } 120 | } 121 | 122 | 123 | public static class InitializeException extends RuntimeException { 124 | 125 | private static final long serialVersionUID = 424757273075028708L; 126 | 127 | public InitializeException(String message, Throwable cause) { 128 | super(message, cause); 129 | } 130 | 131 | public InitializeException(String message) { 132 | super(message); 133 | } 134 | 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /java/src/main/java/org/burningwave/jvm/util/TempFileHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | package org.burningwave.jvm.util; 30 | 31 | import java.io.Closeable; 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.util.UUID; 35 | 36 | import io.github.toolfactory.jvm.util.Strings; 37 | 38 | public class TempFileHolder implements Closeable { 39 | private static File mainTemporaryFolder; 40 | private File file = null; 41 | boolean isPosix = false; 42 | 43 | static { 44 | File toDelete = null; 45 | try { 46 | toDelete = File.createTempFile("_BW_TEMP_", "_temp"); 47 | } catch (IOException exception) { 48 | throw new RuntimeException("Unable to create temporary folder", exception); 49 | } 50 | File tempFolder = toDelete.getParentFile(); 51 | File folder = new File(tempFolder.getAbsolutePath() + "/" + "Burningwave" +"/"+ UUID.randomUUID().toString() + "_" + System.currentTimeMillis()); 52 | if (!folder.exists()) { 53 | folder.mkdirs(); 54 | folder.deleteOnExit(); 55 | } 56 | toDelete.delete(); 57 | mainTemporaryFolder = folder; 58 | } 59 | 60 | public TempFileHolder(String fileName) throws IOException { 61 | file = new File(mainTemporaryFolder.getAbsolutePath() + "/" + fileName); 62 | if (file.exists()) { 63 | throw new IllegalArgumentException(Strings.compile("Temporary file {} already exists", file.getAbsolutePath())); 64 | } 65 | file.createNewFile(); 66 | try { 67 | isPosix = file.toPath().getFileSystem().supportedFileAttributeViews().contains("posix"); 68 | } catch (Throwable e) {} 69 | } 70 | 71 | public File getFile() { 72 | return file; 73 | } 74 | 75 | public boolean isPosix() { 76 | return isPosix; 77 | } 78 | 79 | 80 | @Override 81 | public void close() throws IOException { 82 | if (file != null) { 83 | boolean deleted = false; 84 | if (isPosix) { 85 | deleted = file.delete(); 86 | } 87 | if (!deleted) { 88 | file.deleteOnExit(); 89 | } 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /java/src/main/resources/jvm-driver.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This file is derived from ToolFactory JVM driver. 3 | # 4 | # Hosted at: https://github.com/toolfactory/jvm-driver 5 | # 6 | # Modified by: Roberto Gentili 7 | # 8 | # Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | # 10 | # -- 11 | # 12 | # The MIT License (MIT) 13 | # 14 | # Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | # 16 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | # documentation files (the "Software"), to deal in the Software without restriction, including without 18 | # limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | # the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | # conditions: 21 | # 22 | # The above copyright notice and this permission notice shall be included in all copies or substantial 23 | # portions of the Software. 24 | # 25 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | # LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | # EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | # OR OTHER DEALINGS IN THE SOFTWARE. 30 | # 31 | priority-of-this-configuration=1 32 | driver-factory.default-driver.class=io.github.toolfactory.jvm.DefaultDriver 33 | driver-factory.dynamic-driver.class=org.burningwave.jvm.DynamicDriver 34 | driver-factory.hybrid-driver.class=org.burningwave.jvm.HybridDriver 35 | driver-factory.native-driver.class=org.burningwave.jvm.NativeDriver -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/AllTestsSuite.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | 4 | import org.junit.runner.RunWith; 5 | import org.junit.runners.Suite; 6 | 7 | 8 | @RunWith(Suite.class) 9 | @Suite.SuiteClasses({ 10 | DefaultDriverTest.class, 11 | HybridDriverTest.class, 12 | NativeDriverTest.class, 13 | DynamicDriverTest.class 14 | }) 15 | public class AllTestsSuite { 16 | 17 | //For JDK 7 testing 18 | public static void main(String[] args) { 19 | new DefaultDriverTest().executeTests(); 20 | new DynamicDriverTest().executeTests(); 21 | new HybridDriverTest().executeTests(); 22 | new NativeDriverTest().executeTests(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/BaseTest.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.lang.reflect.Field; 7 | import java.lang.reflect.Member; 8 | import java.net.URL; 9 | import java.util.ArrayList; 10 | import java.util.Collection; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.Map.Entry; 14 | 15 | 16 | @SuppressWarnings("unused") 17 | abstract class BaseTest { 18 | protected Reflection reflection; 19 | 20 | 21 | //For JDK 7 testing 22 | void executeTests() { 23 | getAndSetDirectVolatileTestOne(); 24 | getConsulterTestOne(); 25 | getDeclaredFieldsTestOne(); 26 | getDeclaredMethodsTestOne(); 27 | getDeclaredConstructorsTestOne(); 28 | allocateInstanceTestOne(); 29 | setAccessibleTestOne(); 30 | invokeTestOne(); 31 | newInstanceTestOne(); 32 | retrieveLoadedClassesTestOne(); 33 | retrieveLoadedPackagesTestOne(); 34 | getClassByNameTestOne(); 35 | retrieveResourcesAsStreamsTestOne(); 36 | convertToBuiltinClassLoader(); 37 | stopThread(); 38 | } 39 | 40 | 41 | abstract Reflection getReflection(); 42 | 43 | 44 | void getAndSetDirectVolatileTestOne() { 45 | try { 46 | Object obj = new Object() { 47 | volatile List objectValue; 48 | volatile short shortValue; 49 | volatile int intValue; 50 | volatile long longValue; 51 | volatile float floatValue; 52 | volatile double doubleValue; 53 | volatile boolean booleanValue; 54 | volatile byte byteValue; 55 | volatile char charValue; 56 | }; 57 | 58 | Reflection reflection = getReflection(); 59 | Field field = reflection.getDeclaredField(obj.getClass(), "objectValue"); 60 | List objectValue = new ArrayList<>(); 61 | reflection.setFieldValue(obj, field, objectValue); 62 | List objectValue2Var = reflection.getFieldValue(obj, field); 63 | assertTrue(objectValue2Var == objectValue); 64 | field = reflection.getDeclaredField(obj.getClass(), "shortValue"); 65 | reflection.setFieldValue(obj, field, (short)1); 66 | short shortValue = reflection.getFieldValue(obj, field); 67 | assertTrue(shortValue == 1); 68 | field = reflection.getDeclaredField(obj.getClass(), "intValue"); 69 | reflection.setFieldValue(obj, field, 2); 70 | int intValue = reflection.getFieldValue(obj, field); 71 | assertTrue(intValue == 2); 72 | field = reflection.getDeclaredField(obj.getClass(), "longValue"); 73 | reflection.setFieldValue(obj, field, 3L); 74 | long longValue = reflection.getFieldValue(obj, field); 75 | assertTrue(longValue == 3L); 76 | field = reflection.getDeclaredField(obj.getClass(), "floatValue"); 77 | reflection.setFieldValue(obj, field, 4f); 78 | float floatValue = reflection.getFieldValue(obj, field); 79 | assertTrue(floatValue == 4f); 80 | field = reflection.getDeclaredField(obj.getClass(), "doubleValue"); 81 | reflection.setFieldValue(obj, field, 5.1d); 82 | double doubleValue = reflection.getFieldValue(obj, field); 83 | assertTrue(doubleValue == 5.1d); 84 | field = reflection.getDeclaredField(obj.getClass(), "booleanValue"); 85 | reflection.setFieldValue(obj, field, true); 86 | boolean booleanValue = reflection.getFieldValue(obj, field); 87 | assertTrue(booleanValue); 88 | field = reflection.getDeclaredField(obj.getClass(), "byteValue"); 89 | reflection.setFieldValue(obj, field, (byte)6); 90 | byte byteValue = reflection.getFieldValue(obj, field); 91 | assertTrue(byteValue == 6); 92 | field = reflection.getDeclaredField(obj.getClass(), "charValue"); 93 | reflection.setFieldValue(obj, field, 'a'); 94 | char charValue = reflection.getFieldValue(obj, field); 95 | assertTrue(charValue == 'a'); 96 | 97 | obj = new ClassForTest(); 98 | objectValue = new ArrayList<>(); 99 | field = reflection.getDeclaredField(obj.getClass(), "objectValue"); 100 | reflection.setFieldValue(obj, field, objectValue); 101 | objectValue2Var = reflection.getFieldValue(obj, field); 102 | assertTrue(objectValue2Var == objectValue); 103 | field = reflection.getDeclaredField(obj.getClass(), "shortValue"); 104 | reflection.setFieldValue(obj, field, (short)1); 105 | shortValue = reflection.getFieldValue(obj, field); 106 | assertTrue(shortValue == 1); 107 | field = reflection.getDeclaredField(obj.getClass(), "intValue"); 108 | reflection.setFieldValue(obj, field, 2); 109 | intValue = reflection.getFieldValue(obj, field); 110 | assertTrue(intValue == 2); 111 | field = reflection.getDeclaredField(obj.getClass(), "longValue"); 112 | reflection.setFieldValue(obj, field, 3L); 113 | longValue = reflection.getFieldValue(obj, field); 114 | assertTrue(longValue == 3L); 115 | field = reflection.getDeclaredField(obj.getClass(), "floatValue"); 116 | reflection.setFieldValue(obj, field, 4f); 117 | floatValue = reflection.getFieldValue(obj, field); 118 | assertTrue(floatValue == 4f); 119 | field = reflection.getDeclaredField(obj.getClass(), "doubleValue"); 120 | reflection.setFieldValue(obj, field, 5.1d); 121 | doubleValue = reflection.getFieldValue(obj, field); 122 | assertTrue(doubleValue == 5.1d); 123 | field = reflection.getDeclaredField(obj.getClass(), "booleanValue"); 124 | reflection.setFieldValue(obj, field, true); 125 | booleanValue = reflection.getFieldValue(obj, field); 126 | assertTrue(booleanValue); 127 | field = reflection.getDeclaredField(obj.getClass(), "byteValue"); 128 | reflection.setFieldValue(obj, field, (byte)6); 129 | byteValue = reflection.getFieldValue(obj, field); 130 | assertTrue(byteValue == 6); 131 | field = reflection.getDeclaredField(obj.getClass(), "charValue"); 132 | reflection.setFieldValue(obj, field, 'a'); 133 | charValue = reflection.getFieldValue(obj, field); 134 | assertTrue(charValue == 'a'); 135 | } catch (Throwable exc) { 136 | exc.printStackTrace(); 137 | getReflection().getDriver().throwException(exc); 138 | } 139 | } 140 | 141 | 142 | void getConsulterTestOne() { 143 | try { 144 | getReflection().getDriver().getConsulter(Class.class); 145 | } catch (Throwable exc) { 146 | exc.printStackTrace(); 147 | getReflection().getDriver().throwException(exc); 148 | } 149 | } 150 | 151 | void getDeclaredFieldsTestOne() { 152 | try { 153 | for (Member member : getReflection().getDriver().getDeclaredFields(Class.class)) { 154 | log(member); 155 | } 156 | } catch (Throwable exc) { 157 | exc.printStackTrace(); 158 | getReflection().getDriver().throwException(exc); 159 | } 160 | } 161 | 162 | void getDeclaredMethodsTestOne() { 163 | try { 164 | for (Member member : getReflection().getDriver().getDeclaredMethods(Class.class)) { 165 | log(member); 166 | } 167 | } catch (Throwable exc) { 168 | exc.printStackTrace(); 169 | getReflection().getDriver().throwException(exc); 170 | } 171 | } 172 | 173 | void getDeclaredConstructorsTestOne() { 174 | try { 175 | for (Member member : getReflection().getDriver().getDeclaredConstructors(Class.class)) { 176 | log(member); 177 | } 178 | } catch (Throwable exc) { 179 | exc.printStackTrace(); 180 | getReflection().getDriver().throwException(exc); 181 | } 182 | } 183 | 184 | 185 | void allocateInstanceTestOne() { 186 | try { 187 | log(getReflection().getDriver().allocateInstance(ClassForTest.class).toString()); 188 | } catch (Throwable exc) { 189 | exc.printStackTrace(); 190 | getReflection().getDriver().throwException(exc); 191 | } 192 | } 193 | 194 | 195 | void setAccessibleTestOne() { 196 | try { 197 | ClassForTest object = new ClassForTest(); 198 | Field field = ClassForTest.class.getDeclaredField("intValue"); 199 | getReflection().getDriver().setAccessible(field, true); 200 | log(field.get(object)); 201 | } catch (Throwable exc) { 202 | exc.printStackTrace(); 203 | getReflection().getDriver().throwException(exc); 204 | } 205 | } 206 | 207 | 208 | void invokeTestOne() { 209 | try { 210 | int newValue = 10; 211 | getReflection().getDriver().invoke( 212 | null, 213 | ClassForTest.class.getDeclaredMethod("setIntValue", int.class), 214 | new Object[] {newValue} 215 | ); 216 | assertTrue( 217 | (Integer)getReflection().getDriver().getFieldValue(null, ClassForTest.class.getDeclaredField("intValue")) == newValue 218 | ); 219 | } catch (Throwable exc) { 220 | exc.printStackTrace(); 221 | getReflection().getDriver().throwException(exc); 222 | } 223 | } 224 | 225 | 226 | void newInstanceTestOne() { 227 | try { 228 | int newValue = 20; 229 | getReflection().getDriver().newInstance( 230 | ClassForTest.class.getDeclaredConstructor(int.class), 231 | new Object[] {newValue} 232 | ); 233 | assertTrue( 234 | (Integer)getReflection().getDriver().getFieldValue(null, ClassForTest.class.getDeclaredField("intValue")) == newValue 235 | ); 236 | } catch (Throwable exc) { 237 | exc.printStackTrace(); 238 | getReflection().getDriver().throwException(exc); 239 | } 240 | } 241 | 242 | 243 | void retrieveLoadedClassesTestOne() { 244 | try { 245 | Collection> loadedClasses = getReflection().getDriver().getLoadedClassesRetriever(Thread.currentThread().getContextClassLoader()).get(); 246 | for (Class cls : loadedClasses) { 247 | log(cls.getName()); 248 | } 249 | } catch (Throwable exc) { 250 | exc.printStackTrace(); 251 | getReflection().getDriver().throwException(exc); 252 | } 253 | } 254 | 255 | 256 | void retrieveLoadedPackagesTestOne() { 257 | try { 258 | Map loadedClasses = getReflection().getDriver().retrieveLoadedPackages(Thread.currentThread().getContextClassLoader()); 259 | for (Entry cls : loadedClasses.entrySet()) { 260 | log(cls.getValue().toString()); 261 | } 262 | } catch (Throwable exc) { 263 | exc.printStackTrace(); 264 | getReflection().getDriver().throwException(exc); 265 | } 266 | } 267 | 268 | public void getClassByNameTestOne() { 269 | try { 270 | Class cls = getReflection().getDriver().getClassByName( 271 | "java.lang.AssertionStatusDirectives", false, 272 | this.getClass().getClassLoader(), this.getClass()); 273 | log(cls); 274 | } catch (Throwable exc) { 275 | exc.printStackTrace(); 276 | getReflection().getDriver().throwException(exc); 277 | } 278 | } 279 | 280 | public void retrieveResourcesAsStreamsTestOne() { 281 | try { 282 | Collection loadedClasses = getReflection().getDriver().getResources( 283 | "jvm-driver.properties", 284 | false, 285 | Thread.currentThread().getContextClassLoader() 286 | ); 287 | for (URL entry : loadedClasses) { 288 | log(entry.getPath()); 289 | } 290 | } catch (Throwable exc) { 291 | exc.printStackTrace(); 292 | getReflection().getDriver().throwException(exc); 293 | } 294 | } 295 | 296 | public void convertToBuiltinClassLoader() { 297 | try { 298 | log(getReflection().getDriver().convertToBuiltinClassLoader(new ClassLoader() {})); 299 | } catch (Throwable exc) { 300 | exc.printStackTrace(); 301 | getReflection().getDriver().throwException(exc); 302 | } 303 | } 304 | 305 | public void stopThread() { 306 | try { 307 | Thread thread = new Thread(new Runnable() { 308 | 309 | @Override 310 | public void run() { 311 | while (true) { 312 | log(Thread.currentThread().getName() + " - " + System.currentTimeMillis()); 313 | try { 314 | Thread.sleep(500); 315 | } catch (InterruptedException e) { 316 | e.printStackTrace(); 317 | } 318 | } 319 | } 320 | 321 | }, "StopThreadTestThread"); 322 | thread.start(); 323 | Thread.sleep(5000); 324 | getReflection().getDriver().stop(thread); 325 | Thread.sleep(2000); 326 | log(thread + " - " + thread.getState()); 327 | } catch (Throwable exc) { 328 | exc.printStackTrace(); 329 | getReflection().getDriver().throwException(exc); 330 | } 331 | } 332 | 333 | private void log(Object value) { 334 | System.out.println(value != null ? value.toString() : "null"); 335 | } 336 | 337 | private static class ClassForTest { 338 | 339 | private static volatile List objectValue; 340 | private static volatile short shortValue; 341 | private static volatile int intValue; 342 | private static volatile long longValue; 343 | private static volatile float floatValue; 344 | private static volatile double doubleValue; 345 | private static volatile boolean booleanValue; 346 | private static volatile byte byteValue; 347 | private static volatile char charValue; 348 | 349 | private ClassForTest() {} 350 | 351 | private ClassForTest(int value) { 352 | setIntValue(value); 353 | } 354 | 355 | private static void setIntValue(int value) { 356 | intValue = value; 357 | } 358 | }; 359 | 360 | } 361 | -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/DefaultDriverTest.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | 7 | public class DefaultDriverTest extends BaseTest { 8 | 9 | //For JDK 7 testing 10 | public static void main(String[] args) { 11 | new DefaultDriverTest().executeTests(); 12 | } 13 | 14 | @Override 15 | Reflection getReflection() { 16 | if (reflection == null) { 17 | try { 18 | reflection = Reflection.Factory.getNewWithDefaultDriver(); 19 | } catch (Throwable exc) { 20 | exc.printStackTrace(); 21 | throw new RuntimeException(exc); 22 | } 23 | } 24 | return reflection; 25 | } 26 | 27 | 28 | @Override 29 | @Test 30 | public void getConsulterTestOne() { 31 | super.getConsulterTestOne(); 32 | } 33 | 34 | 35 | @Override 36 | @Test 37 | public void getAndSetDirectVolatileTestOne() { 38 | super.getAndSetDirectVolatileTestOne(); 39 | } 40 | 41 | 42 | @Override 43 | @Test 44 | public void getDeclaredFieldsTestOne() { 45 | super.getDeclaredFieldsTestOne(); 46 | } 47 | 48 | 49 | @Override 50 | @Test 51 | public void getDeclaredMethodsTestOne() { 52 | super.getDeclaredMethodsTestOne(); 53 | } 54 | 55 | 56 | @Override 57 | @Test 58 | public void getDeclaredConstructorsTestOne() { 59 | super.getDeclaredConstructorsTestOne(); 60 | } 61 | 62 | 63 | @Override 64 | @Test 65 | public void allocateInstanceTestOne() { 66 | super.allocateInstanceTestOne(); 67 | } 68 | 69 | 70 | @Override 71 | @Test 72 | public void setAccessibleTestOne() { 73 | super.setAccessibleTestOne(); 74 | } 75 | 76 | 77 | @Override 78 | @Test 79 | public void invokeTestOne() { 80 | super.invokeTestOne(); 81 | } 82 | 83 | 84 | @Override 85 | @Test 86 | public void newInstanceTestOne() { 87 | super.newInstanceTestOne(); 88 | } 89 | 90 | 91 | @Override 92 | @Test 93 | public void retrieveLoadedClassesTestOne() { 94 | super.retrieveLoadedClassesTestOne(); 95 | } 96 | 97 | 98 | @Override 99 | @Test 100 | public void retrieveLoadedPackagesTestOne() { 101 | super.retrieveLoadedPackagesTestOne(); 102 | } 103 | 104 | 105 | @Override 106 | @Test 107 | public void retrieveResourcesAsStreamsTestOne() { 108 | super.retrieveResourcesAsStreamsTestOne(); 109 | } 110 | 111 | @Override 112 | @Test 113 | public void getClassByNameTestOne() { 114 | super.getClassByNameTestOne(); 115 | } 116 | 117 | @Override 118 | @Test 119 | public void convertToBuiltinClassLoader() { 120 | super.convertToBuiltinClassLoader(); 121 | } 122 | 123 | @Override 124 | @Test 125 | public void stopThread() { 126 | super.stopThread(); 127 | } 128 | 129 | } -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/DynamicDriverTest.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | 7 | public class DynamicDriverTest extends BaseTest { 8 | 9 | //For JDK 7 testing 10 | public static void main(String[] args) { 11 | new DynamicDriverTest().executeTests(); 12 | } 13 | 14 | @Override 15 | Reflection getReflection() { 16 | if (reflection == null) { 17 | try { 18 | reflection = Reflection.Factory.getNewWithDynamicDriver(); 19 | } catch (Throwable exc) { 20 | exc.printStackTrace(); 21 | throw new RuntimeException(exc); 22 | } 23 | } 24 | return reflection; 25 | } 26 | 27 | 28 | @Override 29 | @Test 30 | public void getConsulterTestOne() { 31 | super.getConsulterTestOne(); 32 | } 33 | 34 | 35 | @Override 36 | @Test 37 | public void getAndSetDirectVolatileTestOne() { 38 | super.getAndSetDirectVolatileTestOne(); 39 | } 40 | 41 | 42 | @Override 43 | @Test 44 | public void getDeclaredFieldsTestOne() { 45 | super.getDeclaredFieldsTestOne(); 46 | } 47 | 48 | 49 | @Override 50 | @Test 51 | public void getDeclaredMethodsTestOne() { 52 | super.getDeclaredMethodsTestOne(); 53 | } 54 | 55 | 56 | @Override 57 | @Test 58 | public void getDeclaredConstructorsTestOne() { 59 | super.getDeclaredConstructorsTestOne(); 60 | } 61 | 62 | 63 | @Override 64 | @Test 65 | public void allocateInstanceTestOne() { 66 | super.allocateInstanceTestOne(); 67 | } 68 | 69 | 70 | @Override 71 | @Test 72 | public void setAccessibleTestOne() { 73 | super.setAccessibleTestOne(); 74 | } 75 | 76 | 77 | @Override 78 | @Test 79 | public void invokeTestOne() { 80 | super.invokeTestOne(); 81 | } 82 | 83 | 84 | @Override 85 | @Test 86 | public void newInstanceTestOne() { 87 | super.newInstanceTestOne(); 88 | } 89 | 90 | 91 | @Override 92 | @Test 93 | public void retrieveLoadedClassesTestOne() { 94 | super.retrieveLoadedClassesTestOne(); 95 | } 96 | 97 | 98 | @Override 99 | @Test 100 | public void retrieveLoadedPackagesTestOne() { 101 | super.retrieveLoadedPackagesTestOne(); 102 | } 103 | 104 | 105 | @Override 106 | @Test 107 | public void retrieveResourcesAsStreamsTestOne() { 108 | super.retrieveResourcesAsStreamsTestOne(); 109 | } 110 | 111 | @Override 112 | @Test 113 | public void getClassByNameTestOne() { 114 | super.getClassByNameTestOne(); 115 | } 116 | 117 | @Override 118 | @Test 119 | public void convertToBuiltinClassLoader() { 120 | super.convertToBuiltinClassLoader(); 121 | } 122 | 123 | @Override 124 | @Test 125 | public void stopThread() { 126 | super.stopThread(); 127 | } 128 | } -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/HybridDriverTest.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | 7 | public class HybridDriverTest extends BaseTest { 8 | 9 | //For JDK 7 testing 10 | public static void main(String[] args) { 11 | new HybridDriverTest().executeTests(); 12 | } 13 | 14 | @Override 15 | Reflection getReflection() { 16 | if (reflection == null) { 17 | try { 18 | reflection = Reflection.Factory.getNewWithHybridDriver(); 19 | } catch (Throwable exc) { 20 | exc.printStackTrace(); 21 | throw new RuntimeException(exc); 22 | } 23 | } 24 | return reflection; 25 | } 26 | 27 | 28 | @Override 29 | @Test 30 | public void getConsulterTestOne() { 31 | super.getConsulterTestOne(); 32 | } 33 | 34 | 35 | @Override 36 | @Test 37 | public void getAndSetDirectVolatileTestOne() { 38 | super.getAndSetDirectVolatileTestOne(); 39 | } 40 | 41 | 42 | @Override 43 | @Test 44 | public void getDeclaredFieldsTestOne() { 45 | super.getDeclaredFieldsTestOne(); 46 | } 47 | 48 | 49 | @Override 50 | @Test 51 | public void getDeclaredMethodsTestOne() { 52 | super.getDeclaredMethodsTestOne(); 53 | } 54 | 55 | 56 | @Override 57 | @Test 58 | public void getDeclaredConstructorsTestOne() { 59 | super.getDeclaredConstructorsTestOne(); 60 | } 61 | 62 | 63 | @Override 64 | @Test 65 | public void allocateInstanceTestOne() { 66 | super.allocateInstanceTestOne(); 67 | } 68 | 69 | 70 | @Override 71 | @Test 72 | public void setAccessibleTestOne() { 73 | super.setAccessibleTestOne(); 74 | } 75 | 76 | 77 | @Override 78 | @Test 79 | public void invokeTestOne() { 80 | super.invokeTestOne(); 81 | } 82 | 83 | 84 | @Override 85 | @Test 86 | public void newInstanceTestOne() { 87 | super.newInstanceTestOne(); 88 | } 89 | 90 | 91 | @Override 92 | @Test 93 | public void retrieveLoadedClassesTestOne() { 94 | super.retrieveLoadedClassesTestOne(); 95 | } 96 | 97 | 98 | @Override 99 | @Test 100 | public void retrieveLoadedPackagesTestOne() { 101 | super.retrieveLoadedPackagesTestOne(); 102 | } 103 | 104 | @Override 105 | @Test 106 | public void retrieveResourcesAsStreamsTestOne() { 107 | super.retrieveResourcesAsStreamsTestOne(); 108 | } 109 | 110 | @Override 111 | @Test 112 | public void getClassByNameTestOne() { 113 | super.getClassByNameTestOne(); 114 | } 115 | 116 | @Override 117 | @Test 118 | public void convertToBuiltinClassLoader() { 119 | super.convertToBuiltinClassLoader(); 120 | } 121 | 122 | @Override 123 | @Test 124 | public void stopThread() { 125 | super.stopThread(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/NativeDriverTest.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | 7 | public class NativeDriverTest extends BaseTest { 8 | 9 | //For JDK 7 testing 10 | public static void main(String[] args) { 11 | new NativeDriverTest().executeTests(); 12 | } 13 | 14 | @Override 15 | Reflection getReflection() { 16 | if (reflection == null) { 17 | try { 18 | reflection = Reflection.Factory.getNewWithNativeDriver(); 19 | } catch (Throwable exc) { 20 | exc.printStackTrace(); 21 | throw new RuntimeException(exc); 22 | } 23 | } 24 | return reflection; 25 | } 26 | 27 | 28 | @Override 29 | @Test 30 | public void getConsulterTestOne() { 31 | super.getConsulterTestOne(); 32 | } 33 | 34 | 35 | @Override 36 | @Test 37 | public void getAndSetDirectVolatileTestOne() { 38 | super.getAndSetDirectVolatileTestOne(); 39 | } 40 | 41 | 42 | @Override 43 | @Test 44 | public void getDeclaredFieldsTestOne() { 45 | super.getDeclaredFieldsTestOne(); 46 | } 47 | 48 | 49 | @Override 50 | @Test 51 | public void getDeclaredMethodsTestOne() { 52 | super.getDeclaredMethodsTestOne(); 53 | } 54 | 55 | 56 | @Override 57 | @Test 58 | public void getDeclaredConstructorsTestOne() { 59 | super.getDeclaredConstructorsTestOne(); 60 | } 61 | 62 | 63 | @Override 64 | @Test 65 | public void allocateInstanceTestOne() { 66 | super.allocateInstanceTestOne(); 67 | } 68 | 69 | 70 | @Override 71 | @Test 72 | public void setAccessibleTestOne() { 73 | super.setAccessibleTestOne(); 74 | } 75 | 76 | 77 | @Override 78 | @Test 79 | public void invokeTestOne() { 80 | super.invokeTestOne(); 81 | } 82 | 83 | 84 | @Override 85 | @Test 86 | public void newInstanceTestOne() { 87 | super.newInstanceTestOne(); 88 | } 89 | 90 | 91 | @Override 92 | @Test 93 | public void retrieveLoadedClassesTestOne() { 94 | super.retrieveLoadedClassesTestOne(); 95 | } 96 | 97 | 98 | @Override 99 | @Test 100 | public void retrieveLoadedPackagesTestOne() { 101 | super.retrieveLoadedPackagesTestOne(); 102 | } 103 | 104 | @Override 105 | @Test 106 | public void retrieveResourcesAsStreamsTestOne() { 107 | super.retrieveResourcesAsStreamsTestOne(); 108 | } 109 | 110 | @Override 111 | @Test 112 | public void getClassByNameTestOne() { 113 | super.getClassByNameTestOne(); 114 | } 115 | 116 | @Override 117 | @Test 118 | public void convertToBuiltinClassLoader() { 119 | super.convertToBuiltinClassLoader(); 120 | } 121 | 122 | @Override 123 | @Test 124 | public void stopThread() { 125 | super.stopThread(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/NativeExecutorTest.java: -------------------------------------------------------------------------------- 1 | package org.burningwave.jvm.test; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertNotNull; 6 | import static org.junit.Assert.assertThrows; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | import java.lang.reflect.Field; 10 | 11 | import org.burningwave.jvm.NativeExecutor; 12 | import org.junit.function.ThrowingRunnable; 13 | import org.junit.jupiter.api.Test; 14 | 15 | public class NativeExecutorTest { 16 | 17 | private static class TestBean { 18 | private static Object sta_obj; 19 | private static byte sta_byte; 20 | private static short sta_short; 21 | private static int sta_int; 22 | private static long sta_long; 23 | private static float sta_float; 24 | private static double sta_double; 25 | private static char sta_char; 26 | private static boolean sta_boolean; 27 | 28 | private Object ins_obj; 29 | private byte ins_byte; 30 | private short ins_short; 31 | private int ins_int; 32 | private long ins_long; 33 | private float ins_float; 34 | private double ins_double; 35 | private char ins_char; 36 | private boolean ins_boolean; 37 | 38 | @Override 39 | public String toString() { 40 | return "TestBean (\n sta_obj=" + sta_obj 41 | + ", sta_byte=" + sta_byte 42 | + ", sta_short=" + sta_short 43 | + ", sta_int=" + sta_int 44 | + ", sta_long=" + sta_long 45 | + ", sta_float=" + sta_float 46 | + ", sta_double=" + sta_double 47 | + ", sta_char=" + sta_char 48 | + ", sta_boolean=" + sta_boolean 49 | + ",\n ins_obj=" + ins_obj 50 | + ", ins_byte=" + ins_byte 51 | + ", ins_short=" + ins_short 52 | + ", ins_int=" + ins_int 53 | + ", ins_long=" + ins_long 54 | + ", ins_float=" + ins_float 55 | + ", ins_double=" + ins_double 56 | + ", ins_char=" + ins_char 57 | + ", ins_boolean=" + ins_boolean 58 | + "\n)"; 59 | } 60 | } 61 | 62 | private static class TestException extends Exception { 63 | private static final long serialVersionUID = 1L; 64 | } 65 | 66 | private static void printBean(TestBean bean) { 67 | System.out.println(bean); 68 | } 69 | 70 | 71 | @Test 72 | public void test() { 73 | final NativeExecutor nativeExecutor = NativeExecutor.getInstance(); 74 | final Class cls = TestBean.class; 75 | TestBean bean = (TestBean) nativeExecutor.allocateInstance(cls); 76 | printBean(bean); 77 | 78 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 79 | @Override 80 | public void run() { 81 | nativeExecutor.throwException(new TestException()); 82 | } 83 | }); 84 | 85 | Field f_sta_obj = nativeExecutor.getDeclaredStaticField(cls, "sta_obj", "Ljava/lang/Object;"); 86 | assertNotNull(f_sta_obj); 87 | Field f_sta_byte = nativeExecutor.getDeclaredStaticField(cls, "sta_byte", "B"); 88 | assertNotNull(f_sta_byte); 89 | Field f_sta_short = nativeExecutor.getDeclaredStaticField(cls, "sta_short", "S"); 90 | assertNotNull(f_sta_short); 91 | Field f_sta_int = nativeExecutor.getDeclaredStaticField(cls, "sta_int", "I"); 92 | assertNotNull(f_sta_int); 93 | Field f_sta_long = nativeExecutor.getDeclaredStaticField(cls, "sta_long", "J"); 94 | assertNotNull(f_sta_long); 95 | Field f_sta_float = nativeExecutor.getDeclaredStaticField(cls, "sta_float", "F"); 96 | assertNotNull(f_sta_float); 97 | Field f_sta_double = nativeExecutor.getDeclaredStaticField(cls, "sta_double", "D"); 98 | assertNotNull(f_sta_double); 99 | Field f_sta_char = nativeExecutor.getDeclaredStaticField(cls, "sta_char", "C"); 100 | assertNotNull(f_sta_char); 101 | Field f_sta_boolean = nativeExecutor.getDeclaredStaticField(cls, "sta_boolean", "Z"); 102 | assertNotNull(f_sta_boolean); 103 | 104 | 105 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 106 | @Override 107 | public void run() throws Throwable { 108 | nativeExecutor.getDeclaredStaticField(cls, "sta_int", "Ljava/lang/Object;"); 109 | } 110 | }); 111 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 112 | @Override 113 | public void run() throws Throwable { 114 | nativeExecutor.getDeclaredStaticField(cls, "sta_i", "I"); 115 | } 116 | }); 117 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 118 | @Override 119 | public void run() throws Throwable { 120 | nativeExecutor.getDeclaredStaticField(cls, "sta_i", "Ljava/lang/Object;"); 121 | } 122 | }); 123 | 124 | 125 | Field f_ins_obj = nativeExecutor.getDeclaredField(cls, "ins_obj", "Ljava/lang/Object;"); 126 | assertNotNull(f_ins_obj); 127 | Field f_ins_byte = nativeExecutor.getDeclaredField(cls, "ins_byte", "B"); 128 | assertNotNull(f_ins_byte); 129 | Field f_ins_short = nativeExecutor.getDeclaredField(cls, "ins_short", "S"); 130 | assertNotNull(f_ins_short); 131 | Field f_ins_int = nativeExecutor.getDeclaredField(cls, "ins_int", "I"); 132 | assertNotNull(f_ins_int); 133 | Field f_ins_long = nativeExecutor.getDeclaredField(cls, "ins_long", "J"); 134 | assertNotNull(f_ins_long); 135 | Field f_ins_float = nativeExecutor.getDeclaredField(cls, "ins_float", "F"); 136 | assertNotNull(f_ins_float); 137 | Field f_ins_double = nativeExecutor.getDeclaredField(cls, "ins_double", "D"); 138 | assertNotNull(f_ins_double); 139 | Field f_ins_char = nativeExecutor.getDeclaredField(cls, "ins_char", "C"); 140 | assertNotNull(f_ins_char); 141 | Field f_ins_boolean = nativeExecutor.getDeclaredField(cls, "ins_boolean", "Z"); 142 | assertNotNull(f_ins_boolean); 143 | 144 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 145 | @Override 146 | public void run() throws Throwable { 147 | nativeExecutor.getDeclaredField(cls, "ins_int", "Ljava/lang/Object;"); 148 | }; 149 | }); 150 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 151 | @Override 152 | public void run() throws Throwable { 153 | nativeExecutor.getDeclaredField(cls, "ins_i", "I"); 154 | }; 155 | }); 156 | assertThrows(NoSuchFieldError.class, new ThrowingRunnable () { 157 | @Override 158 | public void run() throws Throwable { 159 | nativeExecutor.getDeclaredField(cls, "ins_i", "Ljava/lang/Object;"); 160 | }; 161 | }); 162 | 163 | nativeExecutor.setStaticObjectFieldValue(f_sta_obj, "test"); 164 | assertEquals("test", TestBean.sta_obj); 165 | assertEquals("test", nativeExecutor.getStaticObjectFieldValue(f_sta_obj)); 166 | 167 | nativeExecutor.setStaticByteFieldValue(f_sta_byte, (byte) 1); 168 | assertEquals((byte) 1, TestBean.sta_byte); 169 | assertEquals((byte) 1, nativeExecutor.getStaticByteFieldValue(f_sta_byte)); 170 | 171 | nativeExecutor.setStaticShortFieldValue(f_sta_short, (short) 1); 172 | assertEquals((short) 1, TestBean.sta_short); 173 | assertEquals((short) 1, nativeExecutor.getStaticShortFieldValue(f_sta_short)); 174 | 175 | nativeExecutor.setStaticIntFieldValue(f_sta_int, 1); 176 | assertEquals(1, TestBean.sta_int); 177 | assertEquals(1, nativeExecutor.getStaticIntFieldValue(f_sta_int)); 178 | 179 | nativeExecutor.setStaticLongFieldValue(f_sta_long, 1L); 180 | assertEquals(1L, TestBean.sta_long); 181 | assertEquals(1L, nativeExecutor.getStaticLongFieldValue(f_sta_long)); 182 | 183 | nativeExecutor.setStaticFloatFieldValue(f_sta_float, 1.0f); 184 | assertEquals(1.0f, TestBean.sta_float, 0.0f); 185 | assertEquals(1.0f, nativeExecutor.getStaticFloatFieldValue(f_sta_float)); 186 | 187 | nativeExecutor.setStaticDoubleFieldValue(f_sta_double, 1.0); 188 | assertEquals(1.0, TestBean.sta_double, 0.0f); 189 | assertEquals(1.0, nativeExecutor.getStaticDoubleFieldValue(f_sta_double)); 190 | 191 | nativeExecutor.setStaticCharFieldValue(f_sta_char, 'a'); 192 | assertEquals('a', TestBean.sta_char); 193 | assertEquals('a', nativeExecutor.getStaticCharFieldValue(f_sta_char)); 194 | 195 | nativeExecutor.setStaticBooleanFieldValue(f_sta_boolean, true); 196 | assertTrue(TestBean.sta_boolean); 197 | assertTrue(nativeExecutor.getStaticBooleanFieldValue(f_sta_boolean)); 198 | 199 | nativeExecutor.setObjectFieldValue(bean, f_ins_obj, "test"); 200 | assertEquals("test", bean.ins_obj); 201 | assertEquals("test", nativeExecutor.getObjectFieldValue(bean, f_ins_obj)); 202 | 203 | nativeExecutor.setByteFieldValue(bean, f_ins_byte, (byte) 1); 204 | assertEquals((byte) 1, bean.ins_byte); 205 | assertEquals((byte) 1, nativeExecutor.getByteFieldValue(bean, f_ins_byte)); 206 | 207 | nativeExecutor.setShortFieldValue(bean, f_ins_short, (short) 1); 208 | assertEquals((short) 1, bean.ins_short); 209 | assertEquals((short) 1, nativeExecutor.getShortFieldValue(bean, f_ins_short)); 210 | 211 | nativeExecutor.setIntFieldValue(bean, f_ins_int, 1); 212 | assertEquals(1, bean.ins_int); 213 | assertEquals(1, nativeExecutor.getIntFieldValue(bean, f_ins_int)); 214 | 215 | nativeExecutor.setLongFieldValue(bean, f_ins_long, 1L); 216 | assertEquals(1L, bean.ins_long); 217 | assertEquals(1L, nativeExecutor.getLongFieldValue(bean, f_ins_long)); 218 | 219 | nativeExecutor.setFloatFieldValue(bean, f_ins_float, 1.0f); 220 | 221 | assertEquals(1.0f, bean.ins_float, 0.0f); 222 | assertEquals(1.0f, nativeExecutor.getFloatFieldValue(bean, f_ins_float)); 223 | 224 | nativeExecutor.setDoubleFieldValue(bean, f_ins_double, 1.0); 225 | assertEquals(1.0, bean.ins_double, 0.0f); 226 | assertEquals(1.0, nativeExecutor.getDoubleFieldValue(bean, f_ins_double)); 227 | 228 | nativeExecutor.setCharFieldValue(bean, f_ins_char, 'a'); 229 | assertEquals('a', bean.ins_char); 230 | assertEquals('a', nativeExecutor.getCharFieldValue(bean, f_ins_char)); 231 | 232 | nativeExecutor.setBooleanFieldValue(bean, f_ins_boolean, true); 233 | assertTrue(TestBean.sta_boolean); 234 | assertTrue(nativeExecutor.getBooleanFieldValue(bean, f_ins_boolean)); 235 | 236 | printBean(bean); 237 | 238 | 239 | nativeExecutor.setFieldValue(bean, f_sta_obj, "test2"); 240 | assertEquals("test2", TestBean.sta_obj); 241 | assertEquals("test2", nativeExecutor.getFieldValue(bean, f_sta_obj)); 242 | 243 | nativeExecutor.setFieldValue(bean, f_sta_byte, (byte) 2); 244 | assertEquals((byte) 2, TestBean.sta_byte); 245 | assertEquals((byte) 2, nativeExecutor.getFieldValue(bean, f_sta_byte)); 246 | 247 | nativeExecutor.setFieldValue(bean, f_sta_short, (short) 2); 248 | assertEquals((short) 2, TestBean.sta_short); 249 | assertEquals((short) 2, nativeExecutor.getFieldValue(bean, f_sta_short)); 250 | 251 | nativeExecutor.setFieldValue(bean, f_sta_int, 2); 252 | assertEquals(2, TestBean.sta_int); 253 | assertEquals(2, nativeExecutor.getFieldValue(bean, f_sta_int)); 254 | 255 | nativeExecutor.setFieldValue(bean, f_sta_long, 2L); 256 | assertEquals(2L, TestBean.sta_long); 257 | assertEquals(2L, nativeExecutor.getFieldValue(bean, f_sta_long)); 258 | 259 | nativeExecutor.setFieldValue(bean, f_sta_float, 2.0f); 260 | assertEquals(2.0f, TestBean.sta_float, 0.0f); 261 | assertEquals(2.0f, nativeExecutor.getFieldValue(bean, f_sta_float)); 262 | 263 | nativeExecutor.setFieldValue(bean, f_sta_double, 2.0); 264 | assertEquals(2.0, TestBean.sta_double, 0.0f); 265 | assertEquals(2.0, nativeExecutor.getFieldValue(bean, f_sta_double)); 266 | 267 | nativeExecutor.setFieldValue(bean, f_sta_char, 'b'); 268 | assertEquals('b', TestBean.sta_char); 269 | assertEquals('b', nativeExecutor.getFieldValue(bean, f_sta_char)); 270 | 271 | nativeExecutor.setFieldValue(bean, f_sta_boolean, false); 272 | assertFalse(TestBean.sta_boolean); 273 | assertFalse((Boolean) nativeExecutor.getFieldValue(bean, f_sta_boolean)); 274 | 275 | nativeExecutor.setFieldValue(bean, f_ins_obj, "test2"); 276 | assertEquals("test2", bean.ins_obj); 277 | assertEquals("test2", nativeExecutor.getFieldValue(bean, f_ins_obj)); 278 | 279 | nativeExecutor.setFieldValue(bean, f_ins_byte, (byte) 2); 280 | assertEquals((byte) 2, bean.ins_byte); 281 | assertEquals((byte) 2, nativeExecutor.getFieldValue(bean, f_ins_byte)); 282 | 283 | nativeExecutor.setFieldValue(bean, f_ins_short, (short) 2); 284 | assertEquals((short) 2, bean.ins_short); 285 | assertEquals((short) 2, nativeExecutor.getFieldValue(bean, f_ins_short)); 286 | 287 | nativeExecutor.setFieldValue(bean, f_ins_int, 2); 288 | assertEquals(2, bean.ins_int); 289 | assertEquals(2, nativeExecutor.getFieldValue(bean, f_ins_int)); 290 | 291 | nativeExecutor.setFieldValue(bean, f_ins_long, 2L); 292 | assertEquals(2L, bean.ins_long); 293 | assertEquals(2L, nativeExecutor.getFieldValue(bean, f_ins_long)); 294 | 295 | nativeExecutor.setFieldValue(bean, f_ins_float, 2.0f); 296 | assertEquals(2.0f, bean.ins_float, 0.0f); 297 | assertEquals(2.0f, nativeExecutor.getFieldValue(bean, f_ins_float)); 298 | 299 | nativeExecutor.setFieldValue(bean, f_ins_double, 2.0); 300 | assertEquals(2.0, bean.ins_double, 0.0f); 301 | assertEquals(2.0, nativeExecutor.getFieldValue(bean, f_ins_double)); 302 | 303 | nativeExecutor.setFieldValue(bean, f_ins_char, 'b'); 304 | assertEquals('b', bean.ins_char); 305 | assertEquals('b', nativeExecutor.getFieldValue(bean, f_ins_char)); 306 | 307 | nativeExecutor.setFieldValue(bean, f_ins_boolean, false); 308 | assertFalse(TestBean.sta_boolean); 309 | assertFalse((Boolean) nativeExecutor.getFieldValue(bean, f_ins_boolean)); 310 | 311 | printBean(bean); 312 | } 313 | } 314 | -------------------------------------------------------------------------------- /java/src/test/java/org/burningwave/jvm/test/Reflection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is derived from ToolFactory JVM driver. 3 | * 4 | * Hosted at: https://github.com/toolfactory/jvm-driver 5 | * 6 | * Modified by: Roberto Gentili 7 | * 8 | * Modifications hosted at: https://github.com/burningwave/jvm-driver 9 | * 10 | * -- 11 | * 12 | * The MIT License (MIT) 13 | * 14 | * Copyright (c) 2021 Luke Hutchison, Roberto Gentili 15 | * 16 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 17 | * documentation files (the "Software"), to deal in the Software without restriction, including without 18 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 19 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 20 | * conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial 23 | * portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 26 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 27 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 28 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 29 | * OR OTHER DEALINGS IN THE SOFTWARE. 30 | */ 31 | package org.burningwave.jvm.test; 32 | 33 | import java.lang.reflect.Constructor; 34 | import java.lang.reflect.Field; 35 | import java.lang.reflect.Member; 36 | import java.lang.reflect.Method; 37 | import java.util.Collection; 38 | import java.util.HashSet; 39 | import java.util.LinkedHashSet; 40 | import java.util.Set; 41 | 42 | import io.github.toolfactory.jvm.Driver; 43 | import io.github.toolfactory.jvm.function.template.Function; 44 | 45 | public class Reflection { 46 | private Driver driver; 47 | 48 | 49 | private Reflection(Driver driver) { 50 | this.driver = driver; 51 | } 52 | 53 | public Driver getDriver() { 54 | return this.driver; 55 | } 56 | 57 | public Collection getDeclaredMethods(Class cls) { 58 | Set declaredMembers = new LinkedHashSet<>(); 59 | for (Method method : driver.getDeclaredMethods(cls)) { 60 | declaredMembers.add(method); 61 | } 62 | return declaredMembers; 63 | } 64 | 65 | 66 | public Collection getAllMethods(Class cls) { 67 | return getAll( 68 | cls, 69 | new Function, Method[]>() { 70 | @Override 71 | public Method[] apply(Class input) { 72 | return driver.getDeclaredMethods(input); 73 | } 74 | }, 75 | new HashSet>(), 76 | new LinkedHashSet() 77 | ); 78 | } 79 | 80 | public T getFieldValue(Object target, Field field) { 81 | return driver.getFieldValue(target, field); 82 | } 83 | 84 | public void setFieldValue(Object target, Field field, Object value) { 85 | driver.setFieldValue(target, field, value); 86 | } 87 | 88 | 89 | public Field getDeclaredField(Class cls, String name) { 90 | for (Field member : driver.getDeclaredFields(cls)) { 91 | if (member.getName().equals(name)) { 92 | return member; 93 | } 94 | } 95 | return null; 96 | } 97 | 98 | public Collection getDeclaredFields(Class cls) { 99 | Set declaredMembers = new LinkedHashSet<>(); 100 | for (Field member : driver.getDeclaredFields(cls)) { 101 | declaredMembers.add(member); 102 | } 103 | return declaredMembers; 104 | } 105 | 106 | 107 | public Collection getAllFields(Class cls) { 108 | return getAll( 109 | cls, 110 | new Function, Field[]>() { 111 | @Override 112 | public Field[] apply(Class input) { 113 | return driver.getDeclaredFields(input); 114 | } 115 | }, 116 | new HashSet>(), 117 | new LinkedHashSet() 118 | ); 119 | } 120 | 121 | 122 | public Collection> getDeclaredConstructors(Class cls) { 123 | Set> declaredMembers = new LinkedHashSet<>(); 124 | for (Constructor member : driver.getDeclaredConstructors(cls)) { 125 | declaredMembers.add(member); 126 | } 127 | return declaredMembers; 128 | } 129 | 130 | 131 | public Collection> getAllConstructors(Class cls) { 132 | return getAll( 133 | cls, 134 | new Function, Constructor[]>() { 135 | @Override 136 | public Constructor[] apply(Class input) { 137 | return driver.getDeclaredConstructors(input); 138 | } 139 | }, 140 | new HashSet>(), 141 | new LinkedHashSet>() 142 | ); 143 | } 144 | 145 | private Collection getAll( 146 | Class cls, 147 | Function, M[]> memberSupplier, 148 | Collection> visitedInterfaces, 149 | Collection collection 150 | ) { 151 | for (M member : memberSupplier.apply(cls)) { 152 | collection.add(member); 153 | } 154 | for (Class interf : cls.getInterfaces()) { 155 | if (visitedInterfaces.add(interf)) { 156 | getAll(interf, memberSupplier, visitedInterfaces, collection); 157 | } 158 | } 159 | Class superClass = cls.getSuperclass(); 160 | return superClass != null ? 161 | getAll( 162 | superClass, 163 | memberSupplier, 164 | visitedInterfaces, 165 | collection 166 | ) : 167 | collection; 168 | } 169 | 170 | public static class Factory { 171 | 172 | public static Reflection getNew() { 173 | return getNewWith(Driver.Factory.getNew()); 174 | } 175 | 176 | public static Reflection getNewWith(Driver driver) { 177 | return new Reflection(driver); 178 | } 179 | 180 | public static Reflection getNewWithDynamicDriver() { 181 | return getNewWith(Driver.Factory.getNewDynamic()); 182 | } 183 | 184 | public static Reflection getNewWithDefaultDriver() { 185 | return getNewWith(Driver.Factory.getNewDefault()); 186 | } 187 | 188 | public static Reflection getNewWithHybridDriver() { 189 | return getNewWith(Driver.Factory.getNewHybrid()); 190 | } 191 | 192 | public static Reflection getNewWithNativeDriver() { 193 | return getNewWith(Driver.Factory.getNewNative()); 194 | } 195 | } 196 | } 197 | 198 | -------------------------------------------------------------------------------- /launcher/eclipse/Burningwave JVM Driver - Debug attacher.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /launcher/eclipse/Burningwave JVM Driver - build and test with REMOTE DEBUG.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /launcher/eclipse/Burningwave JVM Driver - parent clean package install.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /launcher/eclipse/Burningwave JVM Driver - test.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /native/bin/NativeExecutor-x32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/native/bin/NativeExecutor-x32.dll -------------------------------------------------------------------------------- /native/bin/NativeExecutor-x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/native/bin/NativeExecutor-x64.dll -------------------------------------------------------------------------------- /native/bin/libNativeExecutor-aarch64.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/native/bin/libNativeExecutor-aarch64.so -------------------------------------------------------------------------------- /native/bin/libNativeExecutor-x32.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/native/bin/libNativeExecutor-x32.so -------------------------------------------------------------------------------- /native/bin/libNativeExecutor-x64.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/native/bin/libNativeExecutor-x64.dylib -------------------------------------------------------------------------------- /native/bin/libNativeExecutor-x64.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/burningwave/jvm-driver/4bc338f49debfee207996771449a56b375870bb6/native/bin/libNativeExecutor-x64.so -------------------------------------------------------------------------------- /native/pom.xml: -------------------------------------------------------------------------------- 1 | 29 | 32 | 4.0.0 33 | 34 | 35 | org.burningwave 36 | jvm-driver-parent 37 | ${revision} 38 | 39 | 40 | jvm-driver-native 41 | Burningwave JVM Driver - Native module 42 | 43 | 44 | UTF-8 45 | UTF-8 46 | ${project_jdk_version} 47 | ${project_jdk_version} 48 | ${java.home}/include/ 49 | ${java.home}/lib/ 50 | -O3 -fPIC 51 | -fPIC -shared 52 | NativeExecutor 53 | 54 | 55 | 56 | 57 | mac 58 | 59 | 60 | mac 61 | 62 | 63 | 64 | lib${org.codehaus.mojo.option.gcc-linker.artifact-name} 65 | dylib 66 | ${java.home}/include/darwin/ 67 | 68 | 69 | 70 | unix 71 | 72 | 73 | unix 74 | Linux 75 | 76 | 77 | 78 | lib${org.codehaus.mojo.option.gcc-linker.artifact-name} 79 | so 80 | ${java.home}/include/linux/ 81 | 82 | 83 | 84 | extra-compilation-one 85 | 86 | false 87 | 88 | 89 | 90 | 91 | org.codehaus.mojo 92 | native-maven-plugin 93 | 1.0-alpha-11 94 | true 95 | 96 | generic 97 | ${extra-compilation-one-executable} 98 | ${extra-compilation-one-executable} 99 | 100 | -I ${org.codehaus.mojo.option.spec-include-dir-one} 101 | -I ${org.codehaus.mojo.option.spec-include-dir-two} 102 | 103 | 104 | ${org.codehaus.mojo.option.gcc-compiler.flags} 105 | 106 | 107 | ${org.codehaus.mojo.option.gcc-linker.flags} 108 | -I ${org.codehaus.mojo.option.spec-include-dir-one} 109 | -I ${org.codehaus.mojo.option.spec-include-dir-two} 110 | -I ${org.codehaus.mojo.option.spec-include-dir-three} 111 | 112 | 113 | -lstdc++ 114 | 115 | ${project.basedir}/bin 116 | 117 | 118 | 119 | compile native 120 | compile 121 | 122 | compile 123 | link 124 | 125 | 126 | 127 | 128 | ${basedir}/src/main/c-c++ 129 | 130 | org/burningwave/jvm/NativeEnvironment.cpp 131 | org/burningwave/jvm/NativeExecutor.cpp 132 | 133 | 134 | 135 | ${org.codehaus.mojo.option.gcc-linker.final-name}-${extra-compilation-one-artifact-name-suffix} 136 | ${packaging.type} 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | windows 146 | 147 | 148 | Windows 149 | 150 | 151 | 152 | ${org.codehaus.mojo.option.gcc-linker.artifact-name} 153 | dll 154 | ${java.home}/include/win32/ 155 | -Wl,--kill-at -fPIC -shared -static 156 | 157 | 158 | 159 | windows-x86 160 | 161 | 162 | Windows 163 | 164 | 165 | sun.arch.data.model 166 | 32 167 | 168 | 169 | 170 | -Wl,--kill-at -fPIC -shared -static 171 | 172 | 173 | 174 | debug 175 | 176 | 177 | maven.compiler.debug 178 | true 179 | 180 | 181 | 182 | -O0 -g3 -fPIC 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | maven-antrun-plugin 191 | 3.1.0 192 | 193 | 194 | generate-sources 195 | generate-sources 196 | 197 | 198 | 199 | 200 | 201 | 202 | run 203 | 204 | 205 | 206 | 207 | 208 | org.codehaus.mojo 209 | native-maven-plugin 210 | 1.0-alpha-11 211 | true 212 | 213 | generic 214 | gcc 215 | gcc 216 | 217 | -I ${org.codehaus.mojo.option.spec-include-dir-one} 218 | -I ${org.codehaus.mojo.option.spec-include-dir-two} 219 | 220 | 221 | -m${sun.arch.data.model} 222 | ${org.codehaus.mojo.option.gcc-compiler.flags} 223 | 224 | 225 | ${org.codehaus.mojo.option.gcc-linker.flags} 226 | -I ${org.codehaus.mojo.option.spec-include-dir-one} 227 | -I ${org.codehaus.mojo.option.spec-include-dir-two} 228 | -I ${org.codehaus.mojo.option.spec-include-dir-three} 229 | 230 | 231 | -m${sun.arch.data.model} 232 | -lstdc++ 233 | 234 | ${project.basedir}/bin 235 | 236 | 237 | 238 | compile native 239 | compile 240 | 241 | compile 242 | link 243 | 244 | 245 | 246 | 247 | ${basedir}/src/main/c-c++ 248 | 249 | org/burningwave/jvm/NativeEnvironment.cpp 250 | org/burningwave/jvm/NativeExecutor.cpp 251 | 252 | 253 | 254 | ${org.codehaus.mojo.option.gcc-linker.final-name}-x${sun.arch.data.model} 255 | ${packaging.type} 256 | 257 | 258 | 259 | 260 | 261 | 262 | -------------------------------------------------------------------------------- /native/src/main/c-c++/org/burningwave/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | 30 | #include 31 | 32 | #ifndef org_burningwave_Common_H 33 | #define org_burningwave_Common_H 34 | 35 | #define org_burningwave_Common_PASTER(x,y) x ## _ ## y 36 | #define org_burningwave_Common_EVALUATOR(x,y) org_burningwave_Common_PASTER(x,y) 37 | #define org_burningwave_Common_FUNCTION_NAME_OF(className, functionName) org_burningwave_Common_EVALUATOR(Java, org_burningwave_Common_EVALUATOR(className, functionName)) 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /native/src/main/c-c++/org/burningwave/jvm/NativeEnvironment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | #include "NativeEnvironment.h" 30 | 31 | #ifndef org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR 32 | 33 | #define org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(typeName, jtype) \ 34 | this->jtype ## FieldAccessor = new FieldAccessor( \ 35 | &JNIEnv::Get ## typeName ## Field, &JNIEnv::GetStatic ## typeName ## Field, \ 36 | &JNIEnv::Set ## typeName ## Field, &JNIEnv::SetStatic ## typeName ## Field \ 37 | ); 38 | 39 | #endif 40 | 41 | 42 | #ifndef org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR 43 | 44 | #define org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jtype) \ 45 | delete(this->jtype ## FieldAccessor); \ 46 | this->jtype ## FieldAccessor = NULL; 47 | 48 | #endif 49 | 50 | 51 | NativeEnvironment::NativeEnvironment(JNIEnv* env) { 52 | this->init(env); 53 | } 54 | 55 | 56 | void NativeEnvironment::destroy(JNIEnv* jNIEnv){ 57 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jobject) 58 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jshort) 59 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jint) 60 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jlong) 61 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jfloat) 62 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jdouble) 63 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jboolean) 64 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jbyte) 65 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_DESTRUCTOR(jchar) 66 | } 67 | 68 | 69 | void NativeEnvironment::init(JNIEnv* jNIEnv) { 70 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Object, jobject) 71 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Short, jshort) 72 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Int, jint) 73 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Long, jlong) 74 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Float, jfloat) 75 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Double, jdouble) 76 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Boolean, jboolean) 77 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Byte, jbyte) 78 | org_burningwave_jvm_NativeEnvironment_GENERATE_FIELD_ACCESSOR_INITIALIZATOR(Char, jchar) 79 | } 80 | 81 | 82 | template 83 | FieldAccessor::FieldAccessor( 84 | Type (JNIEnv::*getFieldValueFunction) (jobject, jfieldID), 85 | Type (JNIEnv::*getStaticFieldValueFunction) (jclass, jfieldID), 86 | void (JNIEnv::*setValueFunction) (jobject, jfieldID, Type), 87 | void (JNIEnv::*setStaticValueFunction) (jclass , jfieldID, Type) 88 | ) { 89 | this->getFieldValueFunction = getFieldValueFunction; 90 | this->getStaticFieldValueFunction = getStaticFieldValueFunction; 91 | this->setValueFunction = setValueFunction; 92 | this->setStaticValueFunction = setStaticValueFunction; 93 | } 94 | 95 | 96 | template 97 | FieldAccessor::~FieldAccessor() {} 98 | -------------------------------------------------------------------------------- /native/src/main/c-c++/org/burningwave/jvm/NativeEnvironment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | #include "./../common.h" 30 | 31 | #ifndef org_burningwave_jvm_NativeEnvironment_H 32 | #define org_burningwave_jvm_NativeEnvironment_H 33 | 34 | template 35 | class FieldAccessor { 36 | 37 | public: 38 | FieldAccessor( 39 | Type (JNIEnv::*getFieldValueFunction) (jobject, jfieldID), 40 | Type (JNIEnv::*getStaticFieldValueFunction) (jclass, jfieldID), 41 | void (JNIEnv::*setValueFunction) (jobject, jfieldID, Type), 42 | void (JNIEnv::*setStaticValueFunction) (jclass , jfieldID, Type) 43 | ); 44 | 45 | ~FieldAccessor(); 46 | 47 | Type getValue(JNIEnv* env, jobject target, jobject field); 48 | 49 | Type getStaticValue(JNIEnv* env, jclass target, jobject field); 50 | 51 | void setValue(JNIEnv* env, jobject target, jobject field, Type value); 52 | 53 | void setStaticValue(JNIEnv* env, jclass target, jobject field, Type value); 54 | 55 | private: 56 | Type (JNIEnv::*getFieldValueFunction) (jobject, jfieldID); 57 | Type (JNIEnv::*getStaticFieldValueFunction) (jclass, jfieldID); 58 | void (JNIEnv::*setValueFunction) (jobject, jfieldID, Type); 59 | void (JNIEnv::*setStaticValueFunction) (jclass, jfieldID, Type); 60 | 61 | }; 62 | 63 | class NativeEnvironment { 64 | public: 65 | NativeEnvironment(JNIEnv* env); 66 | 67 | void destroy(JNIEnv* env); 68 | 69 | public: 70 | FieldAccessor* jobjectFieldAccessor; 71 | FieldAccessor* jshortFieldAccessor; 72 | FieldAccessor* jintFieldAccessor; 73 | FieldAccessor* jlongFieldAccessor; 74 | FieldAccessor* jfloatFieldAccessor; 75 | FieldAccessor* jdoubleFieldAccessor; 76 | FieldAccessor* jbooleanFieldAccessor; 77 | FieldAccessor* jbyteFieldAccessor; 78 | FieldAccessor* jcharFieldAccessor; 79 | 80 | void init(JNIEnv*); 81 | }; 82 | 83 | 84 | template 85 | Type FieldAccessor::getValue(JNIEnv* jNIEnv, jobject target, jobject field) { 86 | return (jNIEnv->*getFieldValueFunction)(target, jNIEnv->FromReflectedField(field)); 87 | } 88 | 89 | 90 | template 91 | Type FieldAccessor::getStaticValue(JNIEnv* jNIEnv, jclass target, jobject field) { 92 | return (jNIEnv->*getStaticFieldValueFunction)(target, jNIEnv->FromReflectedField(field)); 93 | } 94 | 95 | 96 | template 97 | void FieldAccessor::setValue(JNIEnv* jNIEnv, jobject target, jobject field, Type value) { 98 | (jNIEnv->*setValueFunction)(target, jNIEnv->FromReflectedField(field), value); 99 | } 100 | 101 | 102 | template 103 | void FieldAccessor::setStaticValue(JNIEnv* jNIEnv, jclass target, jobject field, Type value) { 104 | (jNIEnv->*setStaticValueFunction)(target, jNIEnv->FromReflectedField(field), value); 105 | } 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /native/src/main/c-c++/org/burningwave/jvm/NativeExecutor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | #include "NativeExecutor.h" 30 | #include "NativeEnvironment.h" 31 | 32 | #ifndef org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS 33 | 34 | #define org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(typeName, jtype) \ 35 | JNIEXPORT jtype JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, get ## typeName ## FieldValue0)(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jobject target, jobject field) { \ 36 | return environment->jtype ## FieldAccessor->getValue(jNIEnv, target, field); \ 37 | } \ 38 | JNIEXPORT jtype JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, getStatic ## typeName ## FieldValue0)(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jclass target, jobject field) { \ 39 | return environment->jtype ## FieldAccessor->getStaticValue(jNIEnv, target, field); \ 40 | } \ 41 | JNIEXPORT void JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, set ## typeName ## FieldValue0)(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jobject target, jobject field, jtype value) { \ 42 | environment->jtype ## FieldAccessor->setValue(jNIEnv, target, field, value); \ 43 | } \ 44 | JNIEXPORT void JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, setStatic ## typeName ## FieldValue0)(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jclass target, jobject field, jtype value) { \ 45 | environment->jtype ## FieldAccessor->setStaticValue(jNIEnv, target, field, value); \ 46 | } 47 | 48 | #endif 49 | 50 | #ifndef org_burningwave_jvm_NativeExecutor_GENERATE_DECLARED_FIELD_FUNCTION 51 | 52 | #define org_burningwave_jvm_NativeExecutor_GENERATE_DECLARED_FIELD_FUNCTION(functionName, fieldIdRetriever, staticFlag) \ 53 | JNIEXPORT jobject JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, functionName)(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jclass target, jstring name, jstring signature) { \ 54 | const char* fieldName = jNIEnv->GetStringUTFChars(name, NULL); \ 55 | const char* fieldSignature = jNIEnv->GetStringUTFChars(signature, NULL); \ 56 | jfieldID fieldID = jNIEnv->fieldIdRetriever(target, fieldName, fieldSignature); \ 57 | jNIEnv->ReleaseStringUTFChars(signature, fieldSignature); \ 58 | jNIEnv->ReleaseStringUTFChars(name, fieldName); \ 59 | if (!fieldID) { \ 60 | return NULL; \ 61 | } \ 62 | return jNIEnv->ToReflectedField(target, fieldID, staticFlag); \ 63 | } 64 | 65 | #endif 66 | 67 | NativeEnvironment* environment; 68 | 69 | 70 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { 71 | JNIEnv* jNIEnv = NULL; 72 | if (vm->GetEnv((void**)&jNIEnv, JNI_VERSION_1_6) != JNI_OK) { 73 | return -1; 74 | } 75 | environment = new NativeEnvironment(jNIEnv); 76 | if (jNIEnv->ExceptionOccurred()) { 77 | return -1; 78 | } 79 | return JNI_VERSION_1_6; 80 | } 81 | 82 | JNIEXPORT jobject JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, allocateInstance)(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jclass instanceType) { 83 | return jNIEnv->AllocObject(instanceType); 84 | } 85 | 86 | 87 | JNIEXPORT void JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, throwException)(JNIEnv* jNIEnv, jclass ignored, jthrowable throwable) { 88 | jNIEnv->Throw(throwable); 89 | } 90 | 91 | 92 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Object, jobject) 93 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Short, jshort) 94 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Integer, jint) 95 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Long, jlong) 96 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Float, jfloat) 97 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Double, jdouble) 98 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Boolean, jboolean) 99 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Byte, jbyte) 100 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS(Character, jchar) 101 | 102 | org_burningwave_jvm_NativeExecutor_GENERATE_DECLARED_FIELD_FUNCTION(getDeclaredField0, GetFieldID, JNI_FALSE) 103 | org_burningwave_jvm_NativeExecutor_GENERATE_DECLARED_FIELD_FUNCTION(getDeclaredStaticField0, GetStaticFieldID, JNI_TRUE) 104 | -------------------------------------------------------------------------------- /native/src/main/c-c++/org/burningwave/jvm/NativeExecutor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of Burningwave JVM driver. 3 | * 4 | * Author: Roberto Gentili 5 | * 6 | * Hosted at: https://github.com/burningwave/jvm-driver 7 | * 8 | * -- 9 | * 10 | * The MIT License (MIT) 11 | * 12 | * Copyright (c) 2021 Roberto Gentili 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15 | * documentation files (the "Software"), to deal in the Software without restriction, including without 16 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 17 | * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 18 | * conditions: 19 | * 20 | * The above copyright notice and this permission notice shall be included in all copies or substantial 21 | * portions of the Software. 22 | * 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 24 | * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 25 | * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 27 | * OR OTHER DEALINGS IN THE SOFTWARE. 28 | */ 29 | #include "./../common.h" 30 | 31 | #ifndef org_burningwave_jvm_NativeExecutor_H 32 | #define org_burningwave_jvm_NativeExecutor_H 33 | 34 | #ifndef CLASS_00001_NAME 35 | #define CLASS_00001_NAME org_burningwave_jvm_NativeExecutor 36 | #endif 37 | 38 | #define org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(typeName, jtype) \ 39 | JNIEXPORT jtype JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, get ## typeName ## FieldValue0)(JNIEnv*, jobject, jobject, jobject); \ 40 | JNIEXPORT jtype JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, getStatic ## typeName ## FieldValue0)(JNIEnv*, jobject, jclass, jobject); \ 41 | JNIEXPORT void JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, set ## typeName ## FieldValue0)(JNIEnv*, jobject, jobject, jobject, jtype); \ 42 | JNIEXPORT void JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, setStatic ## typeName ## FieldValue0)(JNIEnv*, jobject, jclass, jobject, jtype); 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | JNIEXPORT jobject JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, getDeclaredField0) 49 | (JNIEnv*, jobject, jclass, jstring, jstring); 50 | 51 | JNIEXPORT jobject JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, getDeclaredStaticField0) 52 | (JNIEnv*, jobject, jclass, jstring, jstring); 53 | 54 | JNIEXPORT jobject JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, allocateInstance) 55 | (JNIEnv*, jobject, jclass); 56 | 57 | JNIEXPORT void JNICALL org_burningwave_Common_FUNCTION_NAME_OF(CLASS_00001_NAME, throwException) 58 | (JNIEnv* , jclass, jthrowable); 59 | 60 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Object, jobject) 61 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Short, jshort) 62 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Integer, jint) 63 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Long, jlong) 64 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Float, jfloat) 65 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Double, jdouble) 66 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Boolean, jboolean) 67 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Byte, jbyte) 68 | org_burningwave_jvm_NativeExecutor_GENERATE_FIELD_ACCESSOR_FUNCTIONS_DECLARATION(Character, jchar) 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 31 | 35 | 4.0.0 36 | 37 | org.burningwave 38 | jvm-driver-parent 39 | ${revision} 40 | 41 | Burningwave JVM Driver 42 | 43 | A driver derived from ToolFactory JVM Driver to allow deep interaction with the JVM without any restrictions 44 | 45 | https://burningwave.github.io/jvm-driver/ 46 | 47 | pom 48 | 49 | 50 | native 51 | java 52 | 53 | 54 | 55 | 56 | MIT License 57 | https://github.com/burningwave/jvm-driver/blob/master/LICENSE 58 | repo 59 | 60 | 61 | 62 | 63 | Burningwave 64 | https://www.burningwave.org/ 65 | 66 | 67 | 68 | 69 | Roberto Gentili 70 | roberto.gentili 71 | info@burningwave.org 72 | Burningwave 73 | https://www.burningwave.org/ 74 | 75 | Administrator 76 | Developer 77 | 78 | 79 | 80 | Alessio Perrotta 81 | info@burningwave.org 82 | Burningwave 83 | https://www.burningwave.org/ 84 | 85 | External relationship manager 86 | Developer 87 | 88 | 89 | 90 | 91 | 92 | Roberto Gentili 93 | 1.0.0 94 | 9 95 | https://burningwave@github.com/burningwave/jvm-driver.git 96 | 97 | 98 | 99 | github.com 100 | https://github.com/burningwave/jvm-driver/issues 101 | 102 | 103 | 104 | 105 | ossrh 106 | https://oss.sonatype.org/content/repositories/snapshots 107 | 108 | 109 | ossrh 110 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 111 | 112 | 113 | 114 | 115 | scm:git:${repository.url} 116 | scm:git:${repository.url} 117 | https://github.com/burningwave/jvm-driver 118 | HEAD 119 | 120 | 121 | --------------------------------------------------------------------------------