diff --git a/.github/workflows/build-vmtool.yaml b/.github/workflows/build-vmtool.yaml new file mode 100644 index 000000000..8c095d640 --- /dev/null +++ b/.github/workflows/build-vmtool.yaml @@ -0,0 +1,55 @@ +name: build vmtool + +on: [push] + +jobs: + linux: + runs-on: ubuntu-18.04 + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + - name: Build with Maven + run: ./mvnw package + - uses: actions/upload-artifact@v2 + with: + name: lib + path: arthas-vmtool/target/lib* + + mac: + runs-on: macos-10.15 + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + - name: Build with Maven + run: ./mvnw package + - uses: actions/upload-artifact@v2 + with: + name: lib + path: arthas-vmtool/target/lib* + + windows: + runs-on: windows-2016 + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + - name: Build with Maven + run: ./mvnw package + - uses: actions/upload-artifact@v2 + with: + name: lib + path: arthas-vmtool/target/*.dll \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 000000000..4d4c629a1 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '31 4 * * 4' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'java', 'javascript', 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..c91bbdd91 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,34 @@ +name: release + +on: + push: + tags: + - "arthas-all-*" + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [8] + steps: + - uses: actions/checkout@v2 + - name: Setup java + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Build with Maven + run: mvn clean package -P full + + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + packaging/target/*.zip + packaging/target/*.deb + packaging/target/*.rpm + tunnel-server/target/*fatjar.jar + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..834a1ebf2 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,43 @@ +name: JavaCI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [7, 8, 9, 10, 11 ] + steps: + - uses: actions/checkout@v2 + - name: Setup java + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Build with Maven + run: mvn clean package -P full + + build_jdk_ge_12: + runs-on: ubuntu-latest + strategy: + matrix: + java: [12, 13, 14 ] + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: save java8 home + run: | + export JAVA8_HOME=$JAVA_HOME && echo $JAVA8_HOME + echo "export JAVA8_HOME=$JAVA_HOME" > ~/.testenv + + - name: Setup java + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Build with Maven + run: | + source ~/.testenv + mvn -Dmaven.compiler.fork=true -Dmaven.compiler.executable=$JAVA8_HOME/bin/javac -DJAVA8_HOME=$JAVA8_HOME clean package -P full \ No newline at end of file diff --git a/.gitignore b/.gitignore index 047de2754..ef2356edb 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ site/src/site/sphinx/en/_build dependency-reduced-pom.xml pom.xml.versionsBackup .pmd +**/.flattened-pom.xml +**/.idea/** +**/cmake-build-debug/** diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java old mode 100755 new mode 100644 index fa4f7b499..b901097f2 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -1,22 +1,18 @@ /* -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ - + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import java.net.*; import java.io.*; import java.nio.channels.*; @@ -24,11 +20,12 @@ import java.util.Properties; public class MavenWrapperDownloader { + private static final String WRAPPER_VERSION = "0.5.6"; /** * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. */ - private static final String DEFAULT_DOWNLOAD_URL = - "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; /** * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to @@ -76,13 +73,13 @@ public class MavenWrapperDownloader { } } } - System.out.println("- Downloading from: : " + url); + System.out.println("- Downloading from: " + url); File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); if(!outputFile.getParentFile().exists()) { if(!outputFile.getParentFile().mkdirs()) { System.out.println( - "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); } } System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); @@ -98,6 +95,16 @@ public class MavenWrapperDownloader { } private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } URL website = new URL(urlString); ReadableByteChannel rbc; rbc = Channels.newChannel(website.openStream()); diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar old mode 100755 new mode 100644 index 01e679973..2cc7d4a55 Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties old mode 100755 new mode 100644 index 00d32aab1..642d572ce --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip \ No newline at end of file +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/.travis.yml b/.travis.yml index 5cc97c207..6ef5be7ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ deploy: - "packaging/target/*.zip" - "packaging/target/*.deb" - "packaging/target/*.rpm" - - "tunnel-server/target/*.jar" + - "tunnel-server/target/*fatjar.jar" skip_cleanup: true on: tags: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b8c0fa233..6668ee145 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -141,8 +141,7 @@ chmod +x /tmp/sphinx.osx-x86_64 * 修改`as.sh`里的版本,最后修改日期, `Bootstrap.java`里的版本,Dockerfile里的版本 * 修改本地的maven settings.xml -* mvn release:prepare -Darguments="-DskipTests -P full" -* mvn release:perform -Darguments="-DskipTests -P full" +* mvn clean deploy -DskipTests -P full -P release 如果在下载 sphinx-binary 出错,参考上面的 全量打包 的说明。 @@ -152,7 +151,8 @@ chmod +x /tmp/sphinx.osx-x86_64 比如下载地址: https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/3.x.x/arthas-packaging-3.x.x-bin.zip -* 需要更新 gh-pages 分支下面的 arthas-boot.jar/arthas-demo.jar/as.sh ,下载 doc.zip,解压覆盖掉文档的更新 +* 打上tag,push tag到仓库上 +* 需要更新 gh-pages 分支下面的 arthas-boot.jar/math-game.jar/as.sh ,下载 doc.zip,解压覆盖掉文档的更新 * 需要更新docker镜像,push新的tag:https://hub.docker.com/r/hengyunabc/arthas/tags?page=1&ordering=last_updated 以 3.1.0 版本为例: diff --git a/Dockerfile b/Dockerfile index 3c7a3cdc8..9a2cb30f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM openjdk:8-jdk-alpine -ARG ARTHAS_VERSION="3.4.3" +ARG ARTHAS_VERSION="3.5.2" ARG MIRROR=false ENV MAVEN_HOST=https://repo1.maven.org/maven2 \ diff --git a/Dockerfile-No-Jdk b/Dockerfile-No-Jdk index 24dd3eefb..d05b47601 100644 --- a/Dockerfile-No-Jdk +++ b/Dockerfile-No-Jdk @@ -1,6 +1,6 @@ FROM alpine -ARG ARTHAS_VERSION="3.4.3" +ARG ARTHAS_VERSION="3.5.2" ARG MIRROR=false ENV MAVEN_HOST=https://repo1.maven.org/maven2 \ diff --git a/README.md b/README.md index 7e4777892..27367fcc8 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ Arthas was built to solve these issues. A developer can troubleshoot your produc * Supports command line interactive mode, with auto-complete feature enabled. * Supports telnet and websocket, which enables both local and remote diagnostics with command line and browsers. * Supports profiler/Flame Graph +* Support get objects in the heap that are instances of the specified class. * Supports JDK 6+. * Supports Linux/Mac/Windows. @@ -89,7 +90,7 @@ You can enter its interactive interface by executing `as.sh`, or execute `as.sh * [Docker](https://arthas.aliyun.com/doc/en/docker.html) * [Arthas Spring Boot Starter](https://arthas.aliyun.com/doc/en/spring-boot-starter.html) * [User cases](https://github.com/alibaba/arthas/issues?q=label%3Auser-case) -* [Questions and answers](https://github.com/alibaba/arthas/issues?utf8=%E2%9C%93&q=label%3Aquestion-answered+) +* [FAQ](https://arthas.aliyun.com/doc/en/faq) * [Compile and debug/How to contribute](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md) * [Release Notes](https://github.com/alibaba/arthas/releases) @@ -182,18 +183,18 @@ public interface Servlet { Memory compiler, compiles `.java` files into `.class` files in memory. ```bash -mc /tmp/Test.java +$ mc /tmp/Test.java ``` -#### redefine +#### retransform -* https://arthas.aliyun.com/doc/en/redefine +* https://arthas.aliyun.com/doc/en/retransform -Load the external `*.class` files to re-define the loaded classes in JVM. +Load the external `*.class` files to retransform/hotswap the loaded classes in JVM. ```bash -redefine /tmp/Test.class -redefine -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class +retransform /tmp/Test.class +retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class ``` #### sc @@ -234,6 +235,29 @@ $ sc -d org.springframework.web.context.support.XmlWebApplicationContext ``` + +#### vmtool + +* https://arthas.aliyun.com/doc/en/vmtool + +Get objects in the heap that are instances of the specified class. + +```bash +$ vmtool --action getInstances --className java.lang.String --limit 10 +@String[][ + @String[com/taobao/arthas/core/shell/session/Session], + @String[com.taobao.arthas.core.shell.session.Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/], + @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], + @String[java/util/concurrent/locks/LockSupport], +] +``` + #### stack * https://arthas.aliyun.com/doc/en/stack @@ -392,130 +416,21 @@ View profiler results under arthas-output via browser: ### Known Users +Arthas has more than 120 registered users, [View All](USERS.md). + Welcome to register the company name in this issue: https://github.com/alibaba/arthas/issues/111 (in order of registration) ![Alibaba](static/alibaba.png) ![Alipay](static/alipay.png) ![Aliyun](static/aliyun.png) ![Taobao](static/taobao.png) -![Tmall](static/tmall.png) -![微医](static/weiyi.png) -![卓越教育](static/zhuoyuejiaoyu.png) -![狐狸金服](static/hulijingfu.png) -![三体云](static/santiyun.png) -![证大文化](static/zhengdawenhua.png) -![连连支付](static/lianlianpay.png) -![Acmedcare+](static/acmedcare.png) -![好慷](static/homeking365_log.png) -![来电科技](static/laidian.png) -![四格互联](static/sigehulian.png) ![ICBC](static/icbc.png) -![陆鹰](static/luying.png) -![玩友时代](static/wangyoushidai.png) -![她社区](static/tashequ.png) -![龙腾出行](static/longtengchuxing.png) -![foscam](static/foscam.png) -![二维火](static/2dfire.png) -![lanxum](static/lanxum_com.png) -![纳里健康](static/ngarihealth.png) -![掌门1对1](static/zhangmen.png) -![offcn](static/offcn.png) -![sia](static/sia.png) -![振安资产](static/zhenganzichang.png) -![菠萝](static/bolo.png) -![中通快递](static/zto.png) -![光点科技](static/guangdian.png) -![广州工程技术职业学院](static/gzvtc.jpg) -![mstar](static/mstar.png) -![xwbank](static/xwbank.png) -![imexue](static/imexue.png) -![keking](static/keking.png) -![secoo](static/secoo.jpg) -![viax](static/viax.png) -![yanedu](static/yanedu.png) -![duia](static/duia.png) -![哈啰出行](static/hellobike.png) -![hollycrm](static/hollycrm.png) -![citycloud](static/citycloud.jpg) -![yidianzixun](static/yidianzixun.png) -![神州租车](static/zuche.png) -![天眼查](static/tianyancha.png) -![商脉云](static/anjianyun.png) -![三新文化](static/sanxinbook.png) ![雪球财经](static/xueqiu.png) -![百安居](static/bthome.png) -![安心保险](static/95303.png) -![杭州源诚科技](static/hzyc.png) -![91moxie](static/91moxie.png) -![智慧开源](static/wisdom.png) -![富佳科技](static/fujias.png) -![鼎尖软件](static/dingjiansoft.png) -![广通软件](static/broada.png) -![九鼎瑞信](static/evercreative.jpg) -![小米有品](static/xiaomiyoupin.png) -![欧冶云商](static/ouyeel.png) -![投投科技](static/toutou.png) -![饿了么](static/ele.png) -![58同城](static/58.png) -![上海浪沙](static/runsa.png) -![符律科技](static/fhldtech.png) ![顺丰科技](static/sf.png) -![新致软件](static/newtouch.png) -![北京华宇信息](static/thunisoft.png) -![太平洋保险](static/cpic.png) -![旅享网络](static/risingch.png) -![水滴互联](static/shuidihuzhu.png) ![贝壳找房](static/ke.png) -![嘟嘟牛](static/dodonew.png) -![云幂信息](static/yunmixinxi.png) -![随手科技](static/sui.png) -![妈妈去哪儿](static/mamaqunaer.jpg) -![云实信息](static/realscloud.png) -![BBD数联铭品](static/bbdservice.png) -![伙伴集团](static/zhaoshang800.png) -![数梦工场](static/dtdream.png) -![安恒信息](static/dbappsecurity.png) -![亚信科技](static/asiainfo.png) -![云舒写](static/yunshuxie.png) -![微住](static/iweizhu.png) -![月亮小屋](static/bluemoon.png) -![大搜车](static/souche.png) -![今日图书](static/jinritushu.png) -![竹间智能](static/emotibot.png) -![数字认证](static/bjca.png) -![360金融](static/360jinrong.png) -![安居客](static/anjuke.jpg) -![qunar](static/qunar.png) -![ctrip](static/ctrip.png) -![Tuniu](static/tuniu.png) -![多点](static/dmall.jpg) -![转转](static/zhuanzhuan.jpg) -![金蝶](static/kingdee.jpg) -![华清飞扬](static/sincetimes.jpg) -![神奇视角](static/fasterar.jpg) -![南京昂克软件](static/angke.jpg) -![网盛生意宝](static/netsun.jpg) -![北京登云美业网络](static/idengyun.jpg) -![Holder](static/holder.png) -![立林科技](static/leelen.png) -![爱成长](static/aichengzhang.png) -![嘉云数据](static/clubfactory.png) -![百草味](static/bcw.png) -![青岛优米](static/youmi.png) -![紫光软件](static/unis.png) -![拓保软件](static/tobosoft.png) -![海信集团](static/hisense.png) -![小红唇](static/xiaohongchun.png) -![上海恺英](static/kaiying.png) -![上海慧力](static/xiaohuasheng.png) -![上海喔噻](static/shouqingba.png) ![vipkid](static/vipkid.png) -![宇中科技](static/yuzhong.png) -![蘑菇财富](static/mogu.jpg) -![喔趣科技](static/woqu.png) ![百度凤巢](static/baidufengchao.png) -![喜百年供应链科技](static/xbn.png) -![折耳根科技](static/zheergen.png) +![有赞](static/youzan.png) ### Derivative Projects @@ -532,6 +447,7 @@ This project exists, thanks to all the people who contributed. #### Projects +* [bytekit](https://github.com/alibaba/bytekit) Java Bytecode Kit. * [greys-anatomy](https://github.com/oldmanpushcart/greys-anatomy): The Arthas code base has derived from Greys, we thank for the excellent work done by Greys. * [termd](https://github.com/alibaba/termd): Arthas's terminal implementation is based on termd, an open source library for writing terminal applications in Java. * [crash](https://github.com/crashub/crash): Arthas's text based user interface rendering is based on codes extracted from [here](https://github.com/crashub/crash/tree/1.3.2/shell) diff --git a/README_CN.md b/README_CN.md index 23631b063..a00b53d33 100644 --- a/README_CN.md +++ b/README_CN.md @@ -24,6 +24,7 @@ English version goes [here](README.md). 0. 是否有一个全局视角来查看系统的运行状况? 0. 有什么办法可以监控到JVM的实时运行状态? 0. 怎么快速定位应用的热点,生成火焰图? +0. 怎样直接从JVM内查找某个类的实例? `Arthas`支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。 @@ -78,7 +79,7 @@ curl -L https://arthas.aliyun.com/install.sh | sh * [Docker](https://arthas.aliyun.com/doc/docker.html) * [Arthas Spring Boot Starter](https://arthas.aliyun.com/doc/spring-boot-starter.html) * [用户案例](https://github.com/alibaba/arthas/issues?q=label%3Auser-case) -* [常见问题](https://github.com/alibaba/arthas/issues?utf8=%E2%9C%93&q=label%3Aquestion-answered+) +* [FAQ/常见问题](https://arthas.aliyun.com/doc/faq) * [编译调试/参与贡献](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md) * [Release Notes](https://github.com/alibaba/arthas/releases) * [QQ群/钉钉群](https://arthas.aliyun.com/doc/contact-us.html) @@ -174,14 +175,14 @@ Memory Compiler/内存编译器,编译`.java`文件生成`.class`。 mc /tmp/Test.java ``` -#### redefine -* https://arthas.aliyun.com/doc/redefine +#### retransform +* https://arthas.aliyun.com/doc/retransform -加载外部的`.class`文件,redefine jvm已加载的类。 +加载外部的`.class`文件,retransform 热更新jvm已加载的类。 ```bash -redefine /tmp/Test.class -redefine -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class +retransform /tmp/Test.class +retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class ``` #### sc @@ -221,6 +222,27 @@ $ sc -d org.springframework.web.context.support.XmlWebApplicationContext ``` +#### vmtool + +* https://arthas.aliyun.com/doc/vmtool + +从JVM heap中获取指定类的实例。 + +```bash +$ vmtool --action getInstances --className java.lang.String --limit 10 +@String[][ + @String[com/taobao/arthas/core/shell/session/Session], + @String[com.taobao.arthas.core.shell.session.Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/], + @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], + @String[java/util/concurrent/locks/LockSupport], +] +``` #### stack * https://arthas.aliyun.com/doc/stack @@ -381,132 +403,24 @@ OK ### Known Users +Arthas有超过120家登记用户,[查看全部](USERS.md)。 + 如果您在使用Arthas,请让我们知道,您的使用对我们非常重要:https://github.com/alibaba/arthas/issues/111 (按登记顺序排列) ![Alibaba](static/alibaba.png) ![Alipay](static/alipay.png) ![Aliyun](static/aliyun.png) ![Taobao](static/taobao.png) -![Tmall](static/tmall.png) -![微医](static/weiyi.png) -![卓越教育](static/zhuoyuejiaoyu.png) -![狐狸金服](static/hulijingfu.png) -![三体云](static/santiyun.png) -![证大文化](static/zhengdawenhua.png) -![连连支付](static/lianlianpay.png) -![Acmedcare+](static/acmedcare.png) -![好慷](static/homeking365_log.png) -![来电科技](static/laidian.png) -![四格互联](static/sigehulian.png) ![ICBC](static/icbc.png) -![陆鹰](static/luying.png) -![玩友时代](static/wangyoushidai.png) -![她社区](static/tashequ.png) -![龙腾出行](static/longtengchuxing.png) -![foscam](static/foscam.png) -![二维火](static/2dfire.png) -![lanxum](static/lanxum_com.png) -![纳里健康](static/ngarihealth.png) -![掌门1对1](static/zhangmen.png) -![offcn](static/offcn.png) -![sia](static/sia.png) -![振安资产](static/zhenganzichang.png) -![菠萝](static/bolo.png) -![中通快递](static/zto.png) -![光点科技](static/guangdian.png) -![广州工程技术职业学院](static/gzvtc.jpg) -![mstar](static/mstar.png) -![xwbank](static/xwbank.png) -![imexue](static/imexue.png) -![keking](static/keking.png) -![secoo](static/secoo.jpg) -![viax](static/viax.png) -![yanedu](static/yanedu.png) -![duia](static/duia.png) -![哈啰出行](static/hellobike.png) -![hollycrm](static/hollycrm.png) -![citycloud](static/citycloud.jpg) -![yidianzixun](static/yidianzixun.png) -![神州租车](static/zuche.png) -![天眼查](static/tianyancha.png) -![商脉云](static/anjianyun.png) -![三新文化](static/sanxinbook.png) ![雪球财经](static/xueqiu.png) -![百安居](static/bthome.png) -![安心保险](static/95303.png) -![杭州源诚科技](static/hzyc.png) -![91moxie](static/91moxie.png) -![智慧开源](static/wisdom.png) -![富佳科技](static/fujias.png) -![鼎尖软件](static/dingjiansoft.png) -![广通软件](static/broada.png) -![九鼎瑞信](static/evercreative.jpg) -![小米有品](static/xiaomiyoupin.png) -![欧冶云商](static/ouyeel.png) -![投投科技](static/toutou.png) -![饿了么](static/ele.png) -![58同城](static/58.png) -![上海浪沙](static/runsa.png) -![符律科技](static/fhldtech.png) ![顺丰科技](static/sf.png) -![新致软件](static/newtouch.png) -![北京华宇信息](static/thunisoft.png) -![太平洋保险](static/cpic.png) -![旅享网络](static/risingch.png) -![水滴互联](static/shuidihuzhu.png) ![贝壳找房](static/ke.png) -![嘟嘟牛](static/dodonew.png) -![云幂信息](static/yunmixinxi.png) -![随手科技](static/sui.png) -![妈妈去哪儿](static/mamaqunaer.jpg) -![云实信息](static/realscloud.png) -![BBD数联铭品](static/bbdservice.png) -![伙伴集团](static/zhaoshang800.png) -![数梦工场](static/dtdream.png) -![安恒信息](static/dbappsecurity.png) -![亚信科技](static/asiainfo.png) -![云舒写](static/yunshuxie.png) -![微住](static/iweizhu.png) -![月亮小屋](static/bluemoon.png) -![大搜车](static/souche.png) -![今日图书](static/jinritushu.png) -![竹间智能](static/emotibot.png) -![数字认证](static/bjca.png) -![360金融](static/360jinrong.png) -![安居客](static/anjuke.jpg) -![qunar](static/qunar.png) -![ctrip](static/ctrip.png) -![途牛](static/tuniu.png) -![多点](static/dmall.jpg) -![转转](static/zhuanzhuan.jpg) -![金蝶](static/kingdee.jpg) -![华清飞扬](static/sincetimes.jpg) -![神奇视角](static/fasterar.jpg) -![南京昂克软件](static/angke.jpg) -![网盛生意宝](static/netsun.jpg) -![北京登云美业网络](static/idengyun.jpg) -![Holder](static/holder.png) -![立林科技](static/leelen.png) -![爱成长](static/aichengzhang.png) -![嘉云数据](static/clubfactory.png) -![百草味](static/bcw.png) -![青岛优米](static/youmi.png) -![紫光软件](static/unis.png) -![拓保软件](static/tobosoft.png) -![海信集团](static/hisense.png) -![小红唇](static/xiaohongchun.png) -![上海恺英](static/kaiying.png) -![上海慧力](static/xiaohuasheng.png) -![上海喔噻](static/shouqingba.png) ![vipkid](static/vipkid.png) -![宇中科技](static/yuzhong.png) -![蘑菇财富](static/mogu.jpg) -![喔趣科技](static/woqu.png) ![百度凤巢](static/baidufengchao.png) -![喜百年供应链科技](static/xbn.png) -![折耳根科技](static/zheergen.png) +![有赞](static/youzan.png) + -### 洐生项目 +### 衍生项目 * [Bistoury: 一个集成了Arthas的项目](https://github.com/qunarcorp/bistoury) * [一个使用MVEL脚本的fork](https://github.com/XhinLiang/arthas) @@ -522,6 +436,7 @@ OK #### Projects +* [bytekit](https://github.com/alibaba/bytekit) Java Bytecode Kit,Arthas里字节码增强的内核。 * [greys-anatomy](https://github.com/oldmanpushcart/greys-anatomy): Arthas代码基于Greys二次开发而来,非常感谢Greys之前所有的工作,以及Greys原作者对Arthas提出的意见和建议! * [termd](https://github.com/alibaba/termd): Arthas的命令行实现基于termd开发,是一款优秀的命令行程序开发框架,感谢termd提供了优秀的框架。 * [crash](https://github.com/crashub/crash): Arthas的文本渲染功能基于crash中的文本渲染功能开发,可以从[这里](https://github.com/crashub/crash/tree/1.3.2/shell)看到源码,感谢crash在这方面所做的优秀工作。 diff --git a/USERS.md b/USERS.md new file mode 100644 index 000000000..c82f4d16e --- /dev/null +++ b/USERS.md @@ -0,0 +1,157 @@ +### Known Users + +Welcome to register the company name in this issue: https://github.com/alibaba/arthas/issues/111 (in order of registration) + +![Alibaba](static/alibaba.png) +![Alipay](static/alipay.png) +![Aliyun](static/aliyun.png) +![Taobao](static/taobao.png) +![Tmall](static/tmall.png) +![微医](static/weiyi.png) +![卓越教育](static/zhuoyuejiaoyu.png) +![狐狸金服](static/hulijingfu.png) +![三体云](static/santiyun.png) +![证大文化](static/zhengdawenhua.png) +![连连支付](static/lianlianpay.png) +![Acmedcare+](static/acmedcare.png) +![好慷](static/homeking365_log.png) +![来电科技](static/laidian.png) +![四格互联](static/sigehulian.png) +![ICBC](static/icbc.png) +![陆鹰](static/luying.png) +![玩友时代](static/wangyoushidai.png) +![她社区](static/tashequ.png) +![龙腾出行](static/longtengchuxing.png) +![foscam](static/foscam.png) +![二维火](static/2dfire.png) +![lanxum](static/lanxum_com.png) +![纳里健康](static/ngarihealth.png) +![掌门1对1](static/zhangmen.png) +![offcn](static/offcn.png) +![sia](static/sia.png) +![振安资产](static/zhenganzichang.png) +![菠萝](static/bolo.png) +![中通快递](static/zto.png) +![光点科技](static/guangdian.png) +![广州工程技术职业学院](static/gzvtc.jpg) +![mstar](static/mstar.png) +![xwbank](static/xwbank.png) +![imexue](static/imexue.png) +![keking](static/keking.png) +![secoo](static/secoo.jpg) +![viax](static/viax.png) +![yanedu](static/yanedu.png) +![duia](static/duia.png) +![哈啰出行](static/hellobike.png) +![hollycrm](static/hollycrm.png) +![citycloud](static/citycloud.jpg) +![yidianzixun](static/yidianzixun.png) +![神州租车](static/zuche.png) +![天眼查](static/tianyancha.png) +![商脉云](static/anjianyun.png) +![三新文化](static/sanxinbook.png) +![雪球财经](static/xueqiu.png) +![百安居](static/bthome.png) +![安心保险](static/95303.png) +![杭州源诚科技](static/hzyc.png) +![91moxie](static/91moxie.png) +![智慧开源](static/wisdom.png) +![富佳科技](static/fujias.png) +![鼎尖软件](static/dingjiansoft.png) +![广通软件](static/broada.png) +![九鼎瑞信](static/evercreative.jpg) +![小米有品](static/xiaomiyoupin.png) +![欧冶云商](static/ouyeel.png) +![投投科技](static/toutou.png) +![饿了么](static/ele.png) +![58同城](static/58.png) +![上海浪沙](static/runsa.png) +![符律科技](static/fhldtech.png) +![顺丰科技](static/sf.png) +![新致软件](static/newtouch.png) +![北京华宇信息](static/thunisoft.png) +![太平洋保险](static/cpic.png) +![旅享网络](static/risingch.png) +![水滴互联](static/shuidihuzhu.png) +![贝壳找房](static/ke.png) +![嘟嘟牛](static/dodonew.png) +![云幂信息](static/yunmixinxi.png) +![随手科技](static/sui.png) +![妈妈去哪儿](static/mamaqunaer.jpg) +![云实信息](static/realscloud.png) +![BBD数联铭品](static/bbdservice.png) +![伙伴集团](static/zhaoshang800.png) +![数梦工场](static/dtdream.png) +![安恒信息](static/dbappsecurity.png) +![亚信科技](static/asiainfo.png) +![云舒写](static/yunshuxie.png) +![微住](static/iweizhu.png) +![月亮小屋](static/bluemoon.png) +![大搜车](static/souche.png) +![今日图书](static/jinritushu.png) +![竹间智能](static/emotibot.png) +![数字认证](static/bjca.png) +![360金融](static/360jinrong.png) +![安居客](static/anjuke.jpg) +![qunar](static/qunar.png) +![ctrip](static/ctrip.png) +![Tuniu](static/tuniu.png) +![多点](static/dmall.jpg) +![转转](static/zhuanzhuan.jpg) +![金蝶](static/kingdee.jpg) +![华清飞扬](static/sincetimes.jpg) +![神奇视角](static/fasterar.jpg) +![南京昂克软件](static/angke.jpg) +![网盛生意宝](static/netsun.jpg) +![北京登云美业网络](static/idengyun.jpg) +![Holder](static/holder.png) +![立林科技](static/leelen.png) +![爱成长](static/aichengzhang.png) +![嘉云数据](static/clubfactory.png) +![百草味](static/bcw.png) +![青岛优米](static/youmi.png) +![紫光软件](static/unis.png) +![拓保软件](static/tobosoft.png) +![海信集团](static/hisense.png) +![小红唇](static/xiaohongchun.png) +![上海恺英](static/kaiying.png) +![上海慧力](static/xiaohuasheng.png) +![上海喔噻](static/shouqingba.png) +![vipkid](static/vipkid.png) +![宇中科技](static/yuzhong.png) +![蘑菇财富](static/mogu.jpg) +![喔趣科技](static/woqu.png) +![百度凤巢](static/baidufengchao.png) +![喜百年供应链科技](static/xbn.png) +![折耳根科技](static/zheergen.png) +![qdama](static/qdm_logo.png) +![有赞](static/youzan.png) +![中原银行](static/zhongyuanbank.png) +![CVTE](static/cvte.png) + +* 网易云 +* 派迩信息技术 +* 朴新教育 +* OK智慧教育 +* 云集 +* 业余草科技 +* 家家顺 +* 兰亮 +* 浪潮集团 +* 福建博思软件 +* OPPO +* 中科软科技 +* 大搜车 +* 泰豪软件 +* 中房 +* 安恒信息 +* 武汉力龙 +* 埃欧体科技 +* 创维 +* 启迪出行 +* 大华股份 +* 黄豆伟业 +* 中国有赞 +* 车巴达 +* 华为 +* 云管书 \ No newline at end of file diff --git a/agent/pom.xml b/agent/pom.xml index cb27ac059..d77da1409 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-agent diff --git a/arthas-agent-attach/pom.xml b/arthas-agent-attach/pom.xml index 5d6485e45..efbfaedba 100644 --- a/arthas-agent-attach/pom.xml +++ b/arthas-agent-attach/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-agent-attach @@ -21,8 +21,6 @@ net.bytebuddy byte-buddy-agent - provided - true org.zeroturnaround diff --git a/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java b/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java index 805b55080..bcd0af43b 100644 --- a/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java +++ b/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java @@ -45,7 +45,10 @@ public class ArthasAgent { public ArthasAgent(Map configMap, String arthasHome, boolean slientInit, Instrumentation instrumentation) { - this.configMap = configMap; + if (configMap != null) { + this.configMap = configMap; + } + this.arthasHome = arthasHome; this.slientInit = slientInit; this.instrumentation = instrumentation; diff --git a/arthas-spring-boot-starter/pom.xml b/arthas-spring-boot-starter/pom.xml index c675ede6a..d8a00b8ac 100644 --- a/arthas-spring-boot-starter/pom.xml +++ b/arthas-spring-boot-starter/pom.xml @@ -1,11 +1,11 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml @@ -39,17 +39,6 @@ ${project.version} - - net.bytebuddy - byte-buddy-agent - - - - org.zeroturnaround - zt-zip - jar - - org.springframework.boot spring-boot-starter-actuator diff --git a/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasConfiguration.java b/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasConfiguration.java index f1f466ee7..23f4e716e 100644 --- a/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasConfiguration.java +++ b/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasConfiguration.java @@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.core.env.ConfigurableEnvironment; import com.taobao.arthas.agent.attach.ArthasAgent; @@ -25,6 +26,15 @@ import com.taobao.arthas.agent.attach.ArthasAgent; public class ArthasConfiguration { private static final Logger logger = LoggerFactory.getLogger(ArthasConfiguration.class); + @Autowired + ConfigurableEnvironment environment; + + /** + *
+	 * 1. 提取所有以 arthas.* 开头的配置项,再统一转换为Arthas配置
+	 * 2. 避免某些配置在新版本里支持,但在ArthasProperties里没有配置的情况。
+	 * 
+ */ @ConfigurationProperties(prefix = "arthas") @ConditionalOnMissingBean @Bean @@ -36,7 +46,16 @@ public class ArthasConfiguration { @Bean public ArthasAgent arthasAgent(@Autowired Map arthasConfigMap, @Autowired ArthasProperties arthasProperties) throws Throwable { - arthasConfigMap = StringUtils.removeDashKey(arthasConfigMap); + arthasConfigMap = StringUtils.removeDashKey(arthasConfigMap); + ArthasProperties.updateArthasConfigMapDefaultValue(arthasConfigMap); + /** + * @see org.springframework.boot.context.ContextIdApplicationContextInitializer#getApplicationId(ConfigurableEnvironment) + */ + String appName = environment.getProperty("spring.application.name"); + if (arthasConfigMap.get("appName") == null && appName != null) { + arthasConfigMap.put("appName", appName); + } + // 给配置全加上前缀 Map mapWithPrefix = new HashMap(arthasConfigMap.size()); for (Entry entry : arthasConfigMap.entrySet()) { diff --git a/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java b/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java index dd7bd77b9..03d62add5 100644 --- a/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java +++ b/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java @@ -1,5 +1,7 @@ package com.alibaba.arthas.spring; +import java.util.Map; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -16,6 +18,8 @@ public class ArthasProperties { private String tunnelServer; private String agentId; + private String appName; + /** * report executed command */ @@ -32,6 +36,20 @@ public class ArthasProperties { * when arthas agent init error will throw exception by default. */ private boolean slientInit = false; + /** + * disabled commands,default disable stop command + */ + private String disabledCommands; + private static final String DEFAULT_DISABLEDCOMMANDS = "stop"; + + /** + * 因为 arthasConfigMap 只注入了用户配置的值,没有默认值,因些统一处理补全 + */ + public static void updateArthasConfigMapDefaultValue(Map arthasConfigMap) { + if (!arthasConfigMap.containsKey("disabledCommands")) { + arthasConfigMap.put("disabledCommands", DEFAULT_DISABLEDCOMMANDS); + } + } public String getHome() { return home; @@ -105,4 +123,19 @@ public class ArthasProperties { this.sessionTimeout = sessionTimeout; } + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getDisabledCommands() { + return disabledCommands; + } + + public void setDisabledCommands(String disabledCommands) { + this.disabledCommands = disabledCommands; + } } diff --git a/arthas-vmtool/pom.xml b/arthas-vmtool/pom.xml new file mode 100644 index 000000000..653a58287 --- /dev/null +++ b/arthas-vmtool/pom.xml @@ -0,0 +1,223 @@ + + + 4.0.0 + + arthas-all + com.taobao.arthas + ${revision} + ../pom.xml + + arthas-vmtool + arthas-vmtool + + + + + + macos-amd64 + + + mac + x86_64 + + + + macos + -m64 + libArthasJniLibrary-x64.dylib + + + + + + linux-amd64 + + + linux + amd64 + + + + linux + -m64 + libArthasJniLibrary-x64.so + + + + + + windows-amd64 + + + windows + amd64 + + + + windows + -m64 + libArthasJniLibrary-x64.dll + + + + + org.codehaus.mojo + native-maven-plugin + 1.0-alpha-11 + true + + + + arthas.VmTool + + + ${project.basedir}/src/main/native/head + ${os_name} + + + src/main/native/src + + jni-library.cpp + + + + + generic-classic + g++ + + ${os_arch_option} + -fpic + -shared + -o + + + target + g++ + + ${os_arch_option} + -fpic + -shared + -o + + -static-libstdc++ + -static + + + -o ${project.build.directory}/${lib_name} + + + + + javah + compile + + javah + initialize + compile + link + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + UTF-8 + true + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.codehaus.mojo + native-maven-plugin + 1.0-alpha-11 + true + + + + arthas.VmTool + + + ${project.basedir}/src/main/native/head + ${os_name} + + + src/main/native/src + + jni-library.cpp + + + + + generic-classic + g++ + + ${os_arch_option} + -fpic + -shared + -o + + + target + g++ + + ${os_arch_option} + -fpic + -shared + -o + + + -o ${project.build.directory}/${lib_name} + + + + + javah + compile + + javah + initialize + compile + link + + + + + + + + + + com.taobao.arthas + arthas-common + ${project.version} + + + junit + junit + test + + + org.assertj + assertj-core + test + + + \ No newline at end of file diff --git a/arthas-vmtool/src/main/java/arthas/VmTool.java b/arthas-vmtool/src/main/java/arthas/VmTool.java new file mode 100644 index 000000000..866d47ecb --- /dev/null +++ b/arthas-vmtool/src/main/java/arthas/VmTool.java @@ -0,0 +1,106 @@ +package arthas; + +/** + * @author ZhangZiCheng 2021-02-12 + * @author hengyunabc 2021-04-26 + * @since 3.5.1 + */ +public class VmTool implements VmToolMXBean { + + /** + * 不要修改jni-lib的名称 + */ + public final static String JNI_LIBRARY_NAME = "ArthasJniLibrary"; + + private static VmTool instance; + + private VmTool() { + } + + public static VmTool getInstance() { + return getInstance(null); + } + + public static synchronized VmTool getInstance(String libPath) { + if (instance != null) { + return instance; + } + + if (libPath == null) { + System.loadLibrary(JNI_LIBRARY_NAME); + } else { + System.load(libPath); + } + + instance = new VmTool(); + return instance; + } + + private static synchronized native void forceGc0(); + + /** + * 获取某个class在jvm中当前所有存活实例 + */ + private static synchronized native T[] getInstances0(Class klass, int limit); + + /** + * 统计某个class在jvm中当前所有存活实例的总占用内存,单位:Byte + */ + private static synchronized native long sumInstanceSize0(Class klass); + + /** + * 获取某个实例的占用内存,单位:Byte + */ + private static native long getInstanceSize0(Object instance); + + /** + * 统计某个class在jvm中当前所有存活实例的总个数 + */ + private static synchronized native long countInstances0(Class klass); + + /** + * 获取所有已加载的类 + * @param klass 这个参数必须是 Class.class + * @return + */ + private static synchronized native Class[] getAllLoadedClasses0(Class klass); + + @Override + public void forceGc() { + forceGc0(); + } + + @Override + public T[] getInstances(Class klass) { + return getInstances0(klass, -1); + } + + @Override + public T[] getInstances(Class klass, int limit) { + if (limit == 0) { + throw new IllegalArgumentException("limit can not be 0"); + } + return getInstances0(klass, limit); + } + + @Override + public long sumInstanceSize(Class klass) { + return sumInstanceSize0(klass); + } + + @Override + public long getInstanceSize(Object instance) { + return getInstanceSize0(instance); + } + + @Override + public long countInstances(Class klass) { + return countInstances0(klass); + } + + @Override + public Class[] getAllLoadedClasses() { + return getAllLoadedClasses0(Class.class); + } + +} diff --git a/arthas-vmtool/src/main/java/arthas/VmToolMXBean.java b/arthas-vmtool/src/main/java/arthas/VmToolMXBean.java new file mode 100644 index 000000000..f21000115 --- /dev/null +++ b/arthas-vmtool/src/main/java/arthas/VmToolMXBean.java @@ -0,0 +1,53 @@ +package arthas; + +/** + * VmTool interface for JMX server. How to register VmTool MBean: + * + *
+ * {@code
+ *     ManagementFactory.getPlatformMBeanServer().registerMBean(
+ *             VmTool.getInstance(),
+ *             new ObjectName("arthas:type=VmTool")
+ *     );
+ * }
+ * 
+ * @author hengyunabc 2021-04-26 + */ +public interface VmToolMXBean { + + /** + * https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#ForceGarbageCollection + */ + public void forceGc(); + + public T[] getInstances(Class klass); + + /** + * 获取某个class在jvm中当前所有存活实例 + * @param + * @param klass + * @param limit 如果小于 0 ,则不限制 + * @return + */ + public T[] getInstances(Class klass, int limit); + + /** + * 统计某个class在jvm中当前所有存活实例的总占用内存,单位:Byte + */ + public long sumInstanceSize(Class klass); + + /** + * 获取某个实例的占用内存,单位:Byte + */ + public long getInstanceSize(Object instance); + + /** + * 统计某个class在jvm中当前所有存活实例的总个数 + */ + public long countInstances(Class klass); + + /** + * 获取所有已加载的类 + */ + public Class[] getAllLoadedClasses(); +} diff --git a/arthas-vmtool/src/main/java/arthas/package-info.java b/arthas-vmtool/src/main/java/arthas/package-info.java new file mode 100644 index 000000000..ddf184f18 --- /dev/null +++ b/arthas-vmtool/src/main/java/arthas/package-info.java @@ -0,0 +1,2 @@ + +package arthas; diff --git a/arthas-vmtool/src/main/native/CMakeLists.txt b/arthas-vmtool/src/main/native/CMakeLists.txt new file mode 100644 index 000000000..68c624afb --- /dev/null +++ b/arthas-vmtool/src/main/native/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.17) +project(arthas-native) + +set(CMAKE_CXX_STANDARD 14) + +add_library(jni-lib SHARED src/jni-library.cpp) + +#使用环境变量来include,把不同系统的兼容问题交给jdk解决 +include_directories("include") +include_directories(head) + +IF (WIN32) + include_directories(head/windows) +ELSEIF (APPLE) + include_directories(head/macos) +ELSEIF (common/linux) + include_directories(head/linux) +ENDIF () \ No newline at end of file diff --git a/arthas-vmtool/src/main/native/head/classfile_constants.h b/arthas-vmtool/src/main/native/head/classfile_constants.h new file mode 100755 index 000000000..e5c20cd9a --- /dev/null +++ b/arthas-vmtool/src/main/native/head/classfile_constants.h @@ -0,0 +1,560 @@ +/* + * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef CLASSFILE_CONSTANTS_H +#define CLASSFILE_CONSTANTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Classfile version number for this information */ +#define JVM_CLASSFILE_MAJOR_VERSION 52 +#define JVM_CLASSFILE_MINOR_VERSION 0 + +/* Flags */ + +enum { + JVM_ACC_PUBLIC = 0x0001, + JVM_ACC_PRIVATE = 0x0002, + JVM_ACC_PROTECTED = 0x0004, + JVM_ACC_STATIC = 0x0008, + JVM_ACC_FINAL = 0x0010, + JVM_ACC_SYNCHRONIZED = 0x0020, + JVM_ACC_SUPER = 0x0020, + JVM_ACC_VOLATILE = 0x0040, + JVM_ACC_BRIDGE = 0x0040, + JVM_ACC_TRANSIENT = 0x0080, + JVM_ACC_VARARGS = 0x0080, + JVM_ACC_NATIVE = 0x0100, + JVM_ACC_INTERFACE = 0x0200, + JVM_ACC_ABSTRACT = 0x0400, + JVM_ACC_STRICT = 0x0800, + JVM_ACC_SYNTHETIC = 0x1000, + JVM_ACC_ANNOTATION = 0x2000, + JVM_ACC_ENUM = 0x4000 +}; + +/* Used in newarray instruction. */ + +enum { + JVM_T_BOOLEAN = 4, + JVM_T_CHAR = 5, + JVM_T_FLOAT = 6, + JVM_T_DOUBLE = 7, + JVM_T_BYTE = 8, + JVM_T_SHORT = 9, + JVM_T_INT = 10, + JVM_T_LONG = 11 +}; + +/* Constant Pool Entries */ + +enum { + JVM_CONSTANT_Utf8 = 1, + JVM_CONSTANT_Unicode = 2, /* unused */ + JVM_CONSTANT_Integer = 3, + JVM_CONSTANT_Float = 4, + JVM_CONSTANT_Long = 5, + JVM_CONSTANT_Double = 6, + JVM_CONSTANT_Class = 7, + JVM_CONSTANT_String = 8, + JVM_CONSTANT_Fieldref = 9, + JVM_CONSTANT_Methodref = 10, + JVM_CONSTANT_InterfaceMethodref = 11, + JVM_CONSTANT_NameAndType = 12, + JVM_CONSTANT_MethodHandle = 15, // JSR 292 + JVM_CONSTANT_MethodType = 16, // JSR 292 + JVM_CONSTANT_InvokeDynamic = 18 +}; + +/* JVM_CONSTANT_MethodHandle subtypes */ +enum { + JVM_REF_getField = 1, + JVM_REF_getStatic = 2, + JVM_REF_putField = 3, + JVM_REF_putStatic = 4, + JVM_REF_invokeVirtual = 5, + JVM_REF_invokeStatic = 6, + JVM_REF_invokeSpecial = 7, + JVM_REF_newInvokeSpecial = 8, + JVM_REF_invokeInterface = 9 +}; + +/* StackMapTable type item numbers */ + +enum { + JVM_ITEM_Top = 0, + JVM_ITEM_Integer = 1, + JVM_ITEM_Float = 2, + JVM_ITEM_Double = 3, + JVM_ITEM_Long = 4, + JVM_ITEM_Null = 5, + JVM_ITEM_UninitializedThis = 6, + JVM_ITEM_Object = 7, + JVM_ITEM_Uninitialized = 8 +}; + +/* Type signatures */ + +enum { + JVM_SIGNATURE_ARRAY = '[', + JVM_SIGNATURE_BYTE = 'B', + JVM_SIGNATURE_CHAR = 'C', + JVM_SIGNATURE_CLASS = 'L', + JVM_SIGNATURE_ENDCLASS = ';', + JVM_SIGNATURE_ENUM = 'E', + JVM_SIGNATURE_FLOAT = 'F', + JVM_SIGNATURE_DOUBLE = 'D', + JVM_SIGNATURE_FUNC = '(', + JVM_SIGNATURE_ENDFUNC = ')', + JVM_SIGNATURE_INT = 'I', + JVM_SIGNATURE_LONG = 'J', + JVM_SIGNATURE_SHORT = 'S', + JVM_SIGNATURE_VOID = 'V', + JVM_SIGNATURE_BOOLEAN = 'Z' +}; + +/* Opcodes */ + +enum { + JVM_OPC_nop = 0, + JVM_OPC_aconst_null = 1, + JVM_OPC_iconst_m1 = 2, + JVM_OPC_iconst_0 = 3, + JVM_OPC_iconst_1 = 4, + JVM_OPC_iconst_2 = 5, + JVM_OPC_iconst_3 = 6, + JVM_OPC_iconst_4 = 7, + JVM_OPC_iconst_5 = 8, + JVM_OPC_lconst_0 = 9, + JVM_OPC_lconst_1 = 10, + JVM_OPC_fconst_0 = 11, + JVM_OPC_fconst_1 = 12, + JVM_OPC_fconst_2 = 13, + JVM_OPC_dconst_0 = 14, + JVM_OPC_dconst_1 = 15, + JVM_OPC_bipush = 16, + JVM_OPC_sipush = 17, + JVM_OPC_ldc = 18, + JVM_OPC_ldc_w = 19, + JVM_OPC_ldc2_w = 20, + JVM_OPC_iload = 21, + JVM_OPC_lload = 22, + JVM_OPC_fload = 23, + JVM_OPC_dload = 24, + JVM_OPC_aload = 25, + JVM_OPC_iload_0 = 26, + JVM_OPC_iload_1 = 27, + JVM_OPC_iload_2 = 28, + JVM_OPC_iload_3 = 29, + JVM_OPC_lload_0 = 30, + JVM_OPC_lload_1 = 31, + JVM_OPC_lload_2 = 32, + JVM_OPC_lload_3 = 33, + JVM_OPC_fload_0 = 34, + JVM_OPC_fload_1 = 35, + JVM_OPC_fload_2 = 36, + JVM_OPC_fload_3 = 37, + JVM_OPC_dload_0 = 38, + JVM_OPC_dload_1 = 39, + JVM_OPC_dload_2 = 40, + JVM_OPC_dload_3 = 41, + JVM_OPC_aload_0 = 42, + JVM_OPC_aload_1 = 43, + JVM_OPC_aload_2 = 44, + JVM_OPC_aload_3 = 45, + JVM_OPC_iaload = 46, + JVM_OPC_laload = 47, + JVM_OPC_faload = 48, + JVM_OPC_daload = 49, + JVM_OPC_aaload = 50, + JVM_OPC_baload = 51, + JVM_OPC_caload = 52, + JVM_OPC_saload = 53, + JVM_OPC_istore = 54, + JVM_OPC_lstore = 55, + JVM_OPC_fstore = 56, + JVM_OPC_dstore = 57, + JVM_OPC_astore = 58, + JVM_OPC_istore_0 = 59, + JVM_OPC_istore_1 = 60, + JVM_OPC_istore_2 = 61, + JVM_OPC_istore_3 = 62, + JVM_OPC_lstore_0 = 63, + JVM_OPC_lstore_1 = 64, + JVM_OPC_lstore_2 = 65, + JVM_OPC_lstore_3 = 66, + JVM_OPC_fstore_0 = 67, + JVM_OPC_fstore_1 = 68, + JVM_OPC_fstore_2 = 69, + JVM_OPC_fstore_3 = 70, + JVM_OPC_dstore_0 = 71, + JVM_OPC_dstore_1 = 72, + JVM_OPC_dstore_2 = 73, + JVM_OPC_dstore_3 = 74, + JVM_OPC_astore_0 = 75, + JVM_OPC_astore_1 = 76, + JVM_OPC_astore_2 = 77, + JVM_OPC_astore_3 = 78, + JVM_OPC_iastore = 79, + JVM_OPC_lastore = 80, + JVM_OPC_fastore = 81, + JVM_OPC_dastore = 82, + JVM_OPC_aastore = 83, + JVM_OPC_bastore = 84, + JVM_OPC_castore = 85, + JVM_OPC_sastore = 86, + JVM_OPC_pop = 87, + JVM_OPC_pop2 = 88, + JVM_OPC_dup = 89, + JVM_OPC_dup_x1 = 90, + JVM_OPC_dup_x2 = 91, + JVM_OPC_dup2 = 92, + JVM_OPC_dup2_x1 = 93, + JVM_OPC_dup2_x2 = 94, + JVM_OPC_swap = 95, + JVM_OPC_iadd = 96, + JVM_OPC_ladd = 97, + JVM_OPC_fadd = 98, + JVM_OPC_dadd = 99, + JVM_OPC_isub = 100, + JVM_OPC_lsub = 101, + JVM_OPC_fsub = 102, + JVM_OPC_dsub = 103, + JVM_OPC_imul = 104, + JVM_OPC_lmul = 105, + JVM_OPC_fmul = 106, + JVM_OPC_dmul = 107, + JVM_OPC_idiv = 108, + JVM_OPC_ldiv = 109, + JVM_OPC_fdiv = 110, + JVM_OPC_ddiv = 111, + JVM_OPC_irem = 112, + JVM_OPC_lrem = 113, + JVM_OPC_frem = 114, + JVM_OPC_drem = 115, + JVM_OPC_ineg = 116, + JVM_OPC_lneg = 117, + JVM_OPC_fneg = 118, + JVM_OPC_dneg = 119, + JVM_OPC_ishl = 120, + JVM_OPC_lshl = 121, + JVM_OPC_ishr = 122, + JVM_OPC_lshr = 123, + JVM_OPC_iushr = 124, + JVM_OPC_lushr = 125, + JVM_OPC_iand = 126, + JVM_OPC_land = 127, + JVM_OPC_ior = 128, + JVM_OPC_lor = 129, + JVM_OPC_ixor = 130, + JVM_OPC_lxor = 131, + JVM_OPC_iinc = 132, + JVM_OPC_i2l = 133, + JVM_OPC_i2f = 134, + JVM_OPC_i2d = 135, + JVM_OPC_l2i = 136, + JVM_OPC_l2f = 137, + JVM_OPC_l2d = 138, + JVM_OPC_f2i = 139, + JVM_OPC_f2l = 140, + JVM_OPC_f2d = 141, + JVM_OPC_d2i = 142, + JVM_OPC_d2l = 143, + JVM_OPC_d2f = 144, + JVM_OPC_i2b = 145, + JVM_OPC_i2c = 146, + JVM_OPC_i2s = 147, + JVM_OPC_lcmp = 148, + JVM_OPC_fcmpl = 149, + JVM_OPC_fcmpg = 150, + JVM_OPC_dcmpl = 151, + JVM_OPC_dcmpg = 152, + JVM_OPC_ifeq = 153, + JVM_OPC_ifne = 154, + JVM_OPC_iflt = 155, + JVM_OPC_ifge = 156, + JVM_OPC_ifgt = 157, + JVM_OPC_ifle = 158, + JVM_OPC_if_icmpeq = 159, + JVM_OPC_if_icmpne = 160, + JVM_OPC_if_icmplt = 161, + JVM_OPC_if_icmpge = 162, + JVM_OPC_if_icmpgt = 163, + JVM_OPC_if_icmple = 164, + JVM_OPC_if_acmpeq = 165, + JVM_OPC_if_acmpne = 166, + JVM_OPC_goto = 167, + JVM_OPC_jsr = 168, + JVM_OPC_ret = 169, + JVM_OPC_tableswitch = 170, + JVM_OPC_lookupswitch = 171, + JVM_OPC_ireturn = 172, + JVM_OPC_lreturn = 173, + JVM_OPC_freturn = 174, + JVM_OPC_dreturn = 175, + JVM_OPC_areturn = 176, + JVM_OPC_return = 177, + JVM_OPC_getstatic = 178, + JVM_OPC_putstatic = 179, + JVM_OPC_getfield = 180, + JVM_OPC_putfield = 181, + JVM_OPC_invokevirtual = 182, + JVM_OPC_invokespecial = 183, + JVM_OPC_invokestatic = 184, + JVM_OPC_invokeinterface = 185, + JVM_OPC_invokedynamic = 186, + JVM_OPC_new = 187, + JVM_OPC_newarray = 188, + JVM_OPC_anewarray = 189, + JVM_OPC_arraylength = 190, + JVM_OPC_athrow = 191, + JVM_OPC_checkcast = 192, + JVM_OPC_instanceof = 193, + JVM_OPC_monitorenter = 194, + JVM_OPC_monitorexit = 195, + JVM_OPC_wide = 196, + JVM_OPC_multianewarray = 197, + JVM_OPC_ifnull = 198, + JVM_OPC_ifnonnull = 199, + JVM_OPC_goto_w = 200, + JVM_OPC_jsr_w = 201, + JVM_OPC_MAX = 201 +}; + +/* Opcode length initializer, use with something like: + * unsigned char opcode_length[JVM_OPC_MAX+1] = JVM_OPCODE_LENGTH_INITIALIZER; + */ +#define JVM_OPCODE_LENGTH_INITIALIZER { \ + 1, /* nop */ \ + 1, /* aconst_null */ \ + 1, /* iconst_m1 */ \ + 1, /* iconst_0 */ \ + 1, /* iconst_1 */ \ + 1, /* iconst_2 */ \ + 1, /* iconst_3 */ \ + 1, /* iconst_4 */ \ + 1, /* iconst_5 */ \ + 1, /* lconst_0 */ \ + 1, /* lconst_1 */ \ + 1, /* fconst_0 */ \ + 1, /* fconst_1 */ \ + 1, /* fconst_2 */ \ + 1, /* dconst_0 */ \ + 1, /* dconst_1 */ \ + 2, /* bipush */ \ + 3, /* sipush */ \ + 2, /* ldc */ \ + 3, /* ldc_w */ \ + 3, /* ldc2_w */ \ + 2, /* iload */ \ + 2, /* lload */ \ + 2, /* fload */ \ + 2, /* dload */ \ + 2, /* aload */ \ + 1, /* iload_0 */ \ + 1, /* iload_1 */ \ + 1, /* iload_2 */ \ + 1, /* iload_3 */ \ + 1, /* lload_0 */ \ + 1, /* lload_1 */ \ + 1, /* lload_2 */ \ + 1, /* lload_3 */ \ + 1, /* fload_0 */ \ + 1, /* fload_1 */ \ + 1, /* fload_2 */ \ + 1, /* fload_3 */ \ + 1, /* dload_0 */ \ + 1, /* dload_1 */ \ + 1, /* dload_2 */ \ + 1, /* dload_3 */ \ + 1, /* aload_0 */ \ + 1, /* aload_1 */ \ + 1, /* aload_2 */ \ + 1, /* aload_3 */ \ + 1, /* iaload */ \ + 1, /* laload */ \ + 1, /* faload */ \ + 1, /* daload */ \ + 1, /* aaload */ \ + 1, /* baload */ \ + 1, /* caload */ \ + 1, /* saload */ \ + 2, /* istore */ \ + 2, /* lstore */ \ + 2, /* fstore */ \ + 2, /* dstore */ \ + 2, /* astore */ \ + 1, /* istore_0 */ \ + 1, /* istore_1 */ \ + 1, /* istore_2 */ \ + 1, /* istore_3 */ \ + 1, /* lstore_0 */ \ + 1, /* lstore_1 */ \ + 1, /* lstore_2 */ \ + 1, /* lstore_3 */ \ + 1, /* fstore_0 */ \ + 1, /* fstore_1 */ \ + 1, /* fstore_2 */ \ + 1, /* fstore_3 */ \ + 1, /* dstore_0 */ \ + 1, /* dstore_1 */ \ + 1, /* dstore_2 */ \ + 1, /* dstore_3 */ \ + 1, /* astore_0 */ \ + 1, /* astore_1 */ \ + 1, /* astore_2 */ \ + 1, /* astore_3 */ \ + 1, /* iastore */ \ + 1, /* lastore */ \ + 1, /* fastore */ \ + 1, /* dastore */ \ + 1, /* aastore */ \ + 1, /* bastore */ \ + 1, /* castore */ \ + 1, /* sastore */ \ + 1, /* pop */ \ + 1, /* pop2 */ \ + 1, /* dup */ \ + 1, /* dup_x1 */ \ + 1, /* dup_x2 */ \ + 1, /* dup2 */ \ + 1, /* dup2_x1 */ \ + 1, /* dup2_x2 */ \ + 1, /* swap */ \ + 1, /* iadd */ \ + 1, /* ladd */ \ + 1, /* fadd */ \ + 1, /* dadd */ \ + 1, /* isub */ \ + 1, /* lsub */ \ + 1, /* fsub */ \ + 1, /* dsub */ \ + 1, /* imul */ \ + 1, /* lmul */ \ + 1, /* fmul */ \ + 1, /* dmul */ \ + 1, /* idiv */ \ + 1, /* ldiv */ \ + 1, /* fdiv */ \ + 1, /* ddiv */ \ + 1, /* irem */ \ + 1, /* lrem */ \ + 1, /* frem */ \ + 1, /* drem */ \ + 1, /* ineg */ \ + 1, /* lneg */ \ + 1, /* fneg */ \ + 1, /* dneg */ \ + 1, /* ishl */ \ + 1, /* lshl */ \ + 1, /* ishr */ \ + 1, /* lshr */ \ + 1, /* iushr */ \ + 1, /* lushr */ \ + 1, /* iand */ \ + 1, /* land */ \ + 1, /* ior */ \ + 1, /* lor */ \ + 1, /* ixor */ \ + 1, /* lxor */ \ + 3, /* iinc */ \ + 1, /* i2l */ \ + 1, /* i2f */ \ + 1, /* i2d */ \ + 1, /* l2i */ \ + 1, /* l2f */ \ + 1, /* l2d */ \ + 1, /* f2i */ \ + 1, /* f2l */ \ + 1, /* f2d */ \ + 1, /* d2i */ \ + 1, /* d2l */ \ + 1, /* d2f */ \ + 1, /* i2b */ \ + 1, /* i2c */ \ + 1, /* i2s */ \ + 1, /* lcmp */ \ + 1, /* fcmpl */ \ + 1, /* fcmpg */ \ + 1, /* dcmpl */ \ + 1, /* dcmpg */ \ + 3, /* ifeq */ \ + 3, /* ifne */ \ + 3, /* iflt */ \ + 3, /* ifge */ \ + 3, /* ifgt */ \ + 3, /* ifle */ \ + 3, /* if_icmpeq */ \ + 3, /* if_icmpne */ \ + 3, /* if_icmplt */ \ + 3, /* if_icmpge */ \ + 3, /* if_icmpgt */ \ + 3, /* if_icmple */ \ + 3, /* if_acmpeq */ \ + 3, /* if_acmpne */ \ + 3, /* goto */ \ + 3, /* jsr */ \ + 2, /* ret */ \ + 99, /* tableswitch */ \ + 99, /* lookupswitch */ \ + 1, /* ireturn */ \ + 1, /* lreturn */ \ + 1, /* freturn */ \ + 1, /* dreturn */ \ + 1, /* areturn */ \ + 1, /* return */ \ + 3, /* getstatic */ \ + 3, /* putstatic */ \ + 3, /* getfield */ \ + 3, /* putfield */ \ + 3, /* invokevirtual */ \ + 3, /* invokespecial */ \ + 3, /* invokestatic */ \ + 5, /* invokeinterface */ \ + 5, /* invokedynamic */ \ + 3, /* new */ \ + 2, /* newarray */ \ + 3, /* anewarray */ \ + 1, /* arraylength */ \ + 1, /* athrow */ \ + 3, /* checkcast */ \ + 3, /* instanceof */ \ + 1, /* monitorenter */ \ + 1, /* monitorexit */ \ + 0, /* wide */ \ + 4, /* multianewarray */ \ + 3, /* ifnull */ \ + 3, /* ifnonnull */ \ + 5, /* goto_w */ \ + 5 /* jsr_w */ \ +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* CLASSFILE_CONSTANTS */ diff --git a/arthas-vmtool/src/main/native/head/jawt.h b/arthas-vmtool/src/main/native/head/jawt.h new file mode 100755 index 000000000..f06e80713 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/jawt.h @@ -0,0 +1,299 @@ +/* + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JAWT_H_ +#define _JAVASOFT_JAWT_H_ + +#include "jni.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * AWT native interface (new in JDK 1.3) + * + * The AWT native interface allows a native C or C++ application a means + * by which to access native structures in AWT. This is to facilitate moving + * legacy C and C++ applications to Java and to target the needs of the + * community who, at present, wish to do their own native rendering to canvases + * for performance reasons. Standard extensions such as Java3D also require a + * means to access the underlying native data structures of AWT. + * + * There may be future extensions to this API depending on demand. + * + * A VM does not have to implement this API in order to pass the JCK. + * It is recommended, however, that this API is implemented on VMs that support + * standard extensions, such as Java3D. + * + * Since this is a native API, any program which uses it cannot be considered + * 100% pure java. + */ + +/* + * AWT Native Drawing Surface (JAWT_DrawingSurface). + * + * For each platform, there is a native drawing surface structure. This + * platform-specific structure can be found in jawt_md.h. It is recommended + * that additional platforms follow the same model. It is also recommended + * that VMs on Win32 and Solaris support the existing structures in jawt_md.h. + * + ******************* + * EXAMPLE OF USAGE: + ******************* + * + * In Win32, a programmer wishes to access the HWND of a canvas to perform + * native rendering into it. The programmer has declared the paint() method + * for their canvas subclass to be native: + * + * + * MyCanvas.java: + * + * import java.awt.*; + * + * public class MyCanvas extends Canvas { + * + * static { + * System.loadLibrary("mylib"); + * } + * + * public native void paint(Graphics g); + * } + * + * + * myfile.c: + * + * #include "jawt_md.h" + * #include + * + * JNIEXPORT void JNICALL + * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics) + * { + * JAWT awt; + * JAWT_DrawingSurface* ds; + * JAWT_DrawingSurfaceInfo* dsi; + * JAWT_Win32DrawingSurfaceInfo* dsi_win; + * jboolean result; + * jint lock; + * + * // Get the AWT + * awt.version = JAWT_VERSION_1_3; + * result = JAWT_GetAWT(env, &awt); + * assert(result != JNI_FALSE); + * + * // Get the drawing surface + * ds = awt.GetDrawingSurface(env, canvas); + * assert(ds != NULL); + * + * // Lock the drawing surface + * lock = ds->Lock(ds); + * assert((lock & JAWT_LOCK_ERROR) == 0); + * + * // Get the drawing surface info + * dsi = ds->GetDrawingSurfaceInfo(ds); + * + * // Get the platform-specific drawing info + * dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; + * + * ////////////////////////////// + * // !!! DO PAINTING HERE !!! // + * ////////////////////////////// + * + * // Free the drawing surface info + * ds->FreeDrawingSurfaceInfo(dsi); + * + * // Unlock the drawing surface + * ds->Unlock(ds); + * + * // Free the drawing surface + * awt.FreeDrawingSurface(ds); + * } + * + */ + +/* + * JAWT_Rectangle + * Structure for a native rectangle. + */ +typedef struct jawt_Rectangle { + jint x; + jint y; + jint width; + jint height; +} JAWT_Rectangle; + +struct jawt_DrawingSurface; + +/* + * JAWT_DrawingSurfaceInfo + * Structure for containing the underlying drawing information of a component. + */ +typedef struct jawt_DrawingSurfaceInfo { + /* + * Pointer to the platform-specific information. This can be safely + * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a + * JAWT_X11DrawingSurfaceInfo on Solaris. On Mac OS X this is a + * pointer to a NSObject that conforms to the JAWT_SurfaceLayers + * protocol. See jawt_md.h for details. + */ + void* platformInfo; + /* Cached pointer to the underlying drawing surface */ + struct jawt_DrawingSurface* ds; + /* Bounding rectangle of the drawing surface */ + JAWT_Rectangle bounds; + /* Number of rectangles in the clip */ + jint clipSize; + /* Clip rectangle array */ + JAWT_Rectangle* clip; +} JAWT_DrawingSurfaceInfo; + +#define JAWT_LOCK_ERROR 0x00000001 +#define JAWT_LOCK_CLIP_CHANGED 0x00000002 +#define JAWT_LOCK_BOUNDS_CHANGED 0x00000004 +#define JAWT_LOCK_SURFACE_CHANGED 0x00000008 + +/* + * JAWT_DrawingSurface + * Structure for containing the underlying drawing information of a component. + * All operations on a JAWT_DrawingSurface MUST be performed from the same + * thread as the call to GetDrawingSurface. + */ +typedef struct jawt_DrawingSurface { + /* + * Cached reference to the Java environment of the calling thread. + * If Lock(), Unlock(), GetDrawingSurfaceInfo() or + * FreeDrawingSurfaceInfo() are called from a different thread, + * this data member should be set before calling those functions. + */ + JNIEnv* env; + /* Cached reference to the target object */ + jobject target; + /* + * Lock the surface of the target component for native rendering. + * When finished drawing, the surface must be unlocked with + * Unlock(). This function returns a bitmask with one or more of the + * following values: + * + * JAWT_LOCK_ERROR - When an error has occurred and the surface could not + * be locked. + * + * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed. + * + * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed. + * + * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed + */ + jint (JNICALL *Lock) + (struct jawt_DrawingSurface* ds); + /* + * Get the drawing surface info. + * The value returned may be cached, but the values may change if + * additional calls to Lock() or Unlock() are made. + * Lock() must be called before this can return a valid value. + * Returns NULL if an error has occurred. + * When finished with the returned value, FreeDrawingSurfaceInfo must be + * called. + */ + JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo) + (struct jawt_DrawingSurface* ds); + /* + * Free the drawing surface info. + */ + void (JNICALL *FreeDrawingSurfaceInfo) + (JAWT_DrawingSurfaceInfo* dsi); + /* + * Unlock the drawing surface of the target component for native rendering. + */ + void (JNICALL *Unlock) + (struct jawt_DrawingSurface* ds); +} JAWT_DrawingSurface; + +/* + * JAWT + * Structure for containing native AWT functions. + */ +typedef struct jawt { + /* + * Version of this structure. This must always be set before + * calling JAWT_GetAWT() + */ + jint version; + /* + * Return a drawing surface from a target jobject. This value + * may be cached. + * Returns NULL if an error has occurred. + * Target must be a java.awt.Component (should be a Canvas + * or Window for native rendering). + * FreeDrawingSurface() must be called when finished with the + * returned JAWT_DrawingSurface. + */ + JAWT_DrawingSurface* (JNICALL *GetDrawingSurface) + (JNIEnv* env, jobject target); + /* + * Free the drawing surface allocated in GetDrawingSurface. + */ + void (JNICALL *FreeDrawingSurface) + (JAWT_DrawingSurface* ds); + /* + * Since 1.4 + * Locks the entire AWT for synchronization purposes + */ + void (JNICALL *Lock)(JNIEnv* env); + /* + * Since 1.4 + * Unlocks the entire AWT for synchronization purposes + */ + void (JNICALL *Unlock)(JNIEnv* env); + /* + * Since 1.4 + * Returns a reference to a java.awt.Component from a native + * platform handle. On Windows, this corresponds to an HWND; + * on Solaris and Linux, this is a Drawable. For other platforms, + * see the appropriate machine-dependent header file for a description. + * The reference returned by this function is a local + * reference that is only valid in this environment. + * This function returns a NULL reference if no component could be + * found with matching platform information. + */ + jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo); + +} JAWT; + +/* + * Get the AWT native structure. This function returns JNI_FALSE if + * an error occurs. + */ +_JNI_IMPORT_OR_EXPORT_ +jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt); + +#define JAWT_VERSION_1_3 0x00010003 +#define JAWT_VERSION_1_4 0x00010004 +#define JAWT_VERSION_1_7 0x00010007 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* !_JAVASOFT_JAWT_H_ */ diff --git a/arthas-vmtool/src/main/native/head/jdwpTransport.h b/arthas-vmtool/src/main/native/head/jdwpTransport.h new file mode 100755 index 000000000..4f4b92ede --- /dev/null +++ b/arthas-vmtool/src/main/native/head/jdwpTransport.h @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * Java Debug Wire Protocol Transport Service Provider Interface. + */ + +#ifndef JDWPTRANSPORT_H +#define JDWPTRANSPORT_H + +#include "jni.h" + +enum { + JDWPTRANSPORT_VERSION_1_0 = 0x00010000 +}; + +#ifdef __cplusplus +extern "C" { +#endif + +struct jdwpTransportNativeInterface_; + +struct _jdwpTransportEnv; + +#ifdef __cplusplus +typedef _jdwpTransportEnv jdwpTransportEnv; +#else +typedef const struct jdwpTransportNativeInterface_ *jdwpTransportEnv; +#endif /* __cplusplus */ + +/* + * Errors. Universal errors with JVMTI/JVMDI equivalents keep the + * values the same. + */ +typedef enum { + JDWPTRANSPORT_ERROR_NONE = 0, + JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT = 103, + JDWPTRANSPORT_ERROR_OUT_OF_MEMORY = 110, + JDWPTRANSPORT_ERROR_INTERNAL = 113, + JDWPTRANSPORT_ERROR_ILLEGAL_STATE = 201, + JDWPTRANSPORT_ERROR_IO_ERROR = 202, + JDWPTRANSPORT_ERROR_TIMEOUT = 203, + JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE = 204 +} jdwpTransportError; + + +/* + * Structure to define capabilities + */ +typedef struct { + unsigned int can_timeout_attach :1; + unsigned int can_timeout_accept :1; + unsigned int can_timeout_handshake :1; + unsigned int reserved3 :1; + unsigned int reserved4 :1; + unsigned int reserved5 :1; + unsigned int reserved6 :1; + unsigned int reserved7 :1; + unsigned int reserved8 :1; + unsigned int reserved9 :1; + unsigned int reserved10 :1; + unsigned int reserved11 :1; + unsigned int reserved12 :1; + unsigned int reserved13 :1; + unsigned int reserved14 :1; + unsigned int reserved15 :1; +} JDWPTransportCapabilities; + + +/* + * Structures to define packet layout. + * + * See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html + */ + +enum { + /* + * If additional flags are added that apply to jdwpCmdPacket, + * then debugLoop.c: reader() will need to be updated to + * accept more than JDWPTRANSPORT_FLAGS_NONE. + */ + JDWPTRANSPORT_FLAGS_NONE = 0x0, + JDWPTRANSPORT_FLAGS_REPLY = 0x80 +}; + +typedef struct { + jint len; + jint id; + jbyte flags; + jbyte cmdSet; + jbyte cmd; + jbyte *data; +} jdwpCmdPacket; + +typedef struct { + jint len; + jint id; + jbyte flags; + jshort errorCode; + jbyte *data; +} jdwpReplyPacket; + +typedef struct { + union { + jdwpCmdPacket cmd; + jdwpReplyPacket reply; + } type; +} jdwpPacket; + +/* + * JDWP functions called by the transport. + */ +typedef struct jdwpTransportCallback { + void *(*alloc)(jint numBytes); /* Call this for all allocations */ + void (*free)(void *buffer); /* Call this for all deallocations */ +} jdwpTransportCallback; + +typedef jint (JNICALL *jdwpTransport_OnLoad_t)(JavaVM *jvm, + jdwpTransportCallback *callback, + jint version, + jdwpTransportEnv** env); + + + +/* Function Interface */ + +struct jdwpTransportNativeInterface_ { + /* 1 : RESERVED */ + void *reserved1; + + /* 2 : Get Capabilities */ + jdwpTransportError (JNICALL *GetCapabilities)(jdwpTransportEnv* env, + JDWPTransportCapabilities *capabilities_ptr); + + /* 3 : Attach */ + jdwpTransportError (JNICALL *Attach)(jdwpTransportEnv* env, + const char* address, + jlong attach_timeout, + jlong handshake_timeout); + + /* 4: StartListening */ + jdwpTransportError (JNICALL *StartListening)(jdwpTransportEnv* env, + const char* address, + char** actual_address); + + /* 5: StopListening */ + jdwpTransportError (JNICALL *StopListening)(jdwpTransportEnv* env); + + /* 6: Accept */ + jdwpTransportError (JNICALL *Accept)(jdwpTransportEnv* env, + jlong accept_timeout, + jlong handshake_timeout); + + /* 7: IsOpen */ + jboolean (JNICALL *IsOpen)(jdwpTransportEnv* env); + + /* 8: Close */ + jdwpTransportError (JNICALL *Close)(jdwpTransportEnv* env); + + /* 9: ReadPacket */ + jdwpTransportError (JNICALL *ReadPacket)(jdwpTransportEnv* env, + jdwpPacket *pkt); + + /* 10: Write Packet */ + jdwpTransportError (JNICALL *WritePacket)(jdwpTransportEnv* env, + const jdwpPacket* pkt); + + /* 11: GetLastError */ + jdwpTransportError (JNICALL *GetLastError)(jdwpTransportEnv* env, + char** error); + +}; + + +/* + * Use inlined functions so that C++ code can use syntax such as + * env->Attach("mymachine:5000", 10*1000, 0); + * + * rather than using C's :- + * + * (*env)->Attach(env, "mymachine:5000", 10*1000, 0); + */ +struct _jdwpTransportEnv { + const struct jdwpTransportNativeInterface_ *functions; +#ifdef __cplusplus + + jdwpTransportError GetCapabilities(JDWPTransportCapabilities *capabilities_ptr) { + return functions->GetCapabilities(this, capabilities_ptr); + } + + jdwpTransportError Attach(const char* address, jlong attach_timeout, + jlong handshake_timeout) { + return functions->Attach(this, address, attach_timeout, handshake_timeout); + } + + jdwpTransportError StartListening(const char* address, + char** actual_address) { + return functions->StartListening(this, address, actual_address); + } + + jdwpTransportError StopListening(void) { + return functions->StopListening(this); + } + + jdwpTransportError Accept(jlong accept_timeout, jlong handshake_timeout) { + return functions->Accept(this, accept_timeout, handshake_timeout); + } + + jboolean IsOpen(void) { + return functions->IsOpen(this); + } + + jdwpTransportError Close(void) { + return functions->Close(this); + } + + jdwpTransportError ReadPacket(jdwpPacket *pkt) { + return functions->ReadPacket(this, pkt); + } + + jdwpTransportError WritePacket(const jdwpPacket* pkt) { + return functions->WritePacket(this, pkt); + } + + jdwpTransportError GetLastError(char** error) { + return functions->GetLastError(this, error); + } + + +#endif /* __cplusplus */ +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* JDWPTRANSPORT_H */ diff --git a/arthas-vmtool/src/main/native/head/jni.h b/arthas-vmtool/src/main/native/head/jni.h new file mode 100755 index 000000000..0ffe244b6 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/jni.h @@ -0,0 +1,1960 @@ +/* + * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * We used part of Netscape's Java Runtime Interface (JRI) as the starting + * point of our design and implementation. + */ + +/****************************************************************************** + * Java Runtime Interface + * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved. + *****************************************************************************/ + +#ifndef _JAVASOFT_JNI_H_ +#define _JAVASOFT_JNI_H_ + +#include +#include + +/* jni_md.h contains the machine-dependent typedefs for jbyte, jint + and jlong */ + +#include "jni_md.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * JNI Types + */ + +#ifndef JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H + +typedef unsigned char jboolean; +typedef unsigned short jchar; +typedef short jshort; +typedef float jfloat; +typedef double jdouble; + +typedef jint jsize; + +#ifdef __cplusplus + +class _jobject {}; +class _jclass : public _jobject {}; +class _jthrowable : public _jobject {}; +class _jstring : public _jobject {}; +class _jarray : public _jobject {}; +class _jbooleanArray : public _jarray {}; +class _jbyteArray : public _jarray {}; +class _jcharArray : public _jarray {}; +class _jshortArray : public _jarray {}; +class _jintArray : public _jarray {}; +class _jlongArray : public _jarray {}; +class _jfloatArray : public _jarray {}; +class _jdoubleArray : public _jarray {}; +class _jobjectArray : public _jarray {}; + +typedef _jobject *jobject; +typedef _jclass *jclass; +typedef _jthrowable *jthrowable; +typedef _jstring *jstring; +typedef _jarray *jarray; +typedef _jbooleanArray *jbooleanArray; +typedef _jbyteArray *jbyteArray; +typedef _jcharArray *jcharArray; +typedef _jshortArray *jshortArray; +typedef _jintArray *jintArray; +typedef _jlongArray *jlongArray; +typedef _jfloatArray *jfloatArray; +typedef _jdoubleArray *jdoubleArray; +typedef _jobjectArray *jobjectArray; + +#else + +struct _jobject; + +typedef struct _jobject *jobject; +typedef jobject jclass; +typedef jobject jthrowable; +typedef jobject jstring; +typedef jobject jarray; +typedef jarray jbooleanArray; +typedef jarray jbyteArray; +typedef jarray jcharArray; +typedef jarray jshortArray; +typedef jarray jintArray; +typedef jarray jlongArray; +typedef jarray jfloatArray; +typedef jarray jdoubleArray; +typedef jarray jobjectArray; + +#endif + +typedef jobject jweak; + +typedef union jvalue { + jboolean z; + jbyte b; + jchar c; + jshort s; + jint i; + jlong j; + jfloat f; + jdouble d; + jobject l; +} jvalue; + +struct _jfieldID; +typedef struct _jfieldID *jfieldID; + +struct _jmethodID; +typedef struct _jmethodID *jmethodID; + +/* Return values from jobjectRefType */ +typedef enum _jobjectType { + JNIInvalidRefType = 0, + JNILocalRefType = 1, + JNIGlobalRefType = 2, + JNIWeakGlobalRefType = 3 +} jobjectRefType; + + +#endif /* JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H */ + +/* + * jboolean constants + */ + +#define JNI_FALSE 0 +#define JNI_TRUE 1 + +/* + * possible return values for JNI functions. + */ + +#define JNI_OK 0 /* success */ +#define JNI_ERR (-1) /* unknown error */ +#define JNI_EDETACHED (-2) /* thread detached from the VM */ +#define JNI_EVERSION (-3) /* JNI version error */ +#define JNI_ENOMEM (-4) /* not enough memory */ +#define JNI_EEXIST (-5) /* VM already created */ +#define JNI_EINVAL (-6) /* invalid arguments */ + +/* + * used in ReleaseScalarArrayElements + */ + +#define JNI_COMMIT 1 +#define JNI_ABORT 2 + +/* + * used in RegisterNatives to describe native method name, signature, + * and function pointer. + */ + +typedef struct { + char *name; + char *signature; + void *fnPtr; +} JNINativeMethod; + +/* + * JNI Native Method Interface. + */ + +struct JNINativeInterface_; + +struct JNIEnv_; + +#ifdef __cplusplus +typedef JNIEnv_ JNIEnv; +#else +typedef const struct JNINativeInterface_ *JNIEnv; +#endif + +/* + * JNI Invocation Interface. + */ + +struct JNIInvokeInterface_; + +struct JavaVM_; + +#ifdef __cplusplus +typedef JavaVM_ JavaVM; +#else +typedef const struct JNIInvokeInterface_ *JavaVM; +#endif + +struct JNINativeInterface_ { + void *reserved0; + void *reserved1; + void *reserved2; + + void *reserved3; + jint (JNICALL *GetVersion)(JNIEnv *env); + + jclass (JNICALL *DefineClass) + (JNIEnv *env, const char *name, jobject loader, const jbyte *buf, + jsize len); + jclass (JNICALL *FindClass) + (JNIEnv *env, const char *name); + + jmethodID (JNICALL *FromReflectedMethod) + (JNIEnv *env, jobject method); + jfieldID (JNICALL *FromReflectedField) + (JNIEnv *env, jobject field); + + jobject (JNICALL *ToReflectedMethod) + (JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic); + + jclass (JNICALL *GetSuperclass) + (JNIEnv *env, jclass sub); + jboolean (JNICALL *IsAssignableFrom) + (JNIEnv *env, jclass sub, jclass sup); + + jobject (JNICALL *ToReflectedField) + (JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic); + + jint (JNICALL *Throw) + (JNIEnv *env, jthrowable obj); + jint (JNICALL *ThrowNew) + (JNIEnv *env, jclass clazz, const char *msg); + jthrowable (JNICALL *ExceptionOccurred) + (JNIEnv *env); + void (JNICALL *ExceptionDescribe) + (JNIEnv *env); + void (JNICALL *ExceptionClear) + (JNIEnv *env); + void (JNICALL *FatalError) + (JNIEnv *env, const char *msg); + + jint (JNICALL *PushLocalFrame) + (JNIEnv *env, jint capacity); + jobject (JNICALL *PopLocalFrame) + (JNIEnv *env, jobject result); + + jobject (JNICALL *NewGlobalRef) + (JNIEnv *env, jobject lobj); + void (JNICALL *DeleteGlobalRef) + (JNIEnv *env, jobject gref); + void (JNICALL *DeleteLocalRef) + (JNIEnv *env, jobject obj); + jboolean (JNICALL *IsSameObject) + (JNIEnv *env, jobject obj1, jobject obj2); + jobject (JNICALL *NewLocalRef) + (JNIEnv *env, jobject ref); + jint (JNICALL *EnsureLocalCapacity) + (JNIEnv *env, jint capacity); + + jobject (JNICALL *AllocObject) + (JNIEnv *env, jclass clazz); + jobject (JNICALL *NewObject) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jobject (JNICALL *NewObjectV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jobject (JNICALL *NewObjectA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jclass (JNICALL *GetObjectClass) + (JNIEnv *env, jobject obj); + jboolean (JNICALL *IsInstanceOf) + (JNIEnv *env, jobject obj, jclass clazz); + + jmethodID (JNICALL *GetMethodID) + (JNIEnv *env, jclass clazz, const char *name, const char *sig); + + jobject (JNICALL *CallObjectMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jobject (JNICALL *CallObjectMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jobject (JNICALL *CallObjectMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args); + + jboolean (JNICALL *CallBooleanMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jboolean (JNICALL *CallBooleanMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jboolean (JNICALL *CallBooleanMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args); + + jbyte (JNICALL *CallByteMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jbyte (JNICALL *CallByteMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jbyte (JNICALL *CallByteMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + jchar (JNICALL *CallCharMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jchar (JNICALL *CallCharMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jchar (JNICALL *CallCharMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + jshort (JNICALL *CallShortMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jshort (JNICALL *CallShortMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jshort (JNICALL *CallShortMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + jint (JNICALL *CallIntMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jint (JNICALL *CallIntMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jint (JNICALL *CallIntMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + jlong (JNICALL *CallLongMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jlong (JNICALL *CallLongMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jlong (JNICALL *CallLongMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + jfloat (JNICALL *CallFloatMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jfloat (JNICALL *CallFloatMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jfloat (JNICALL *CallFloatMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + jdouble (JNICALL *CallDoubleMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + jdouble (JNICALL *CallDoubleMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + jdouble (JNICALL *CallDoubleMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args); + + void (JNICALL *CallVoidMethod) + (JNIEnv *env, jobject obj, jmethodID methodID, ...); + void (JNICALL *CallVoidMethodV) + (JNIEnv *env, jobject obj, jmethodID methodID, va_list args); + void (JNICALL *CallVoidMethodA) + (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue * args); + + jobject (JNICALL *CallNonvirtualObjectMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jobject (JNICALL *CallNonvirtualObjectMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jobject (JNICALL *CallNonvirtualObjectMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue * args); + + jboolean (JNICALL *CallNonvirtualBooleanMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jboolean (JNICALL *CallNonvirtualBooleanMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jboolean (JNICALL *CallNonvirtualBooleanMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue * args); + + jbyte (JNICALL *CallNonvirtualByteMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jbyte (JNICALL *CallNonvirtualByteMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jbyte (JNICALL *CallNonvirtualByteMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + jchar (JNICALL *CallNonvirtualCharMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jchar (JNICALL *CallNonvirtualCharMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jchar (JNICALL *CallNonvirtualCharMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + jshort (JNICALL *CallNonvirtualShortMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jshort (JNICALL *CallNonvirtualShortMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jshort (JNICALL *CallNonvirtualShortMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + jint (JNICALL *CallNonvirtualIntMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jint (JNICALL *CallNonvirtualIntMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jint (JNICALL *CallNonvirtualIntMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + jlong (JNICALL *CallNonvirtualLongMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jlong (JNICALL *CallNonvirtualLongMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jlong (JNICALL *CallNonvirtualLongMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + jfloat (JNICALL *CallNonvirtualFloatMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jfloat (JNICALL *CallNonvirtualFloatMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jfloat (JNICALL *CallNonvirtualFloatMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + jdouble (JNICALL *CallNonvirtualDoubleMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + jdouble (JNICALL *CallNonvirtualDoubleMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + jdouble (JNICALL *CallNonvirtualDoubleMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue *args); + + void (JNICALL *CallNonvirtualVoidMethod) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...); + void (JNICALL *CallNonvirtualVoidMethodV) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + va_list args); + void (JNICALL *CallNonvirtualVoidMethodA) + (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, + const jvalue * args); + + jfieldID (JNICALL *GetFieldID) + (JNIEnv *env, jclass clazz, const char *name, const char *sig); + + jobject (JNICALL *GetObjectField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jboolean (JNICALL *GetBooleanField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jbyte (JNICALL *GetByteField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jchar (JNICALL *GetCharField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jshort (JNICALL *GetShortField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jint (JNICALL *GetIntField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jlong (JNICALL *GetLongField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jfloat (JNICALL *GetFloatField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + jdouble (JNICALL *GetDoubleField) + (JNIEnv *env, jobject obj, jfieldID fieldID); + + void (JNICALL *SetObjectField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val); + void (JNICALL *SetBooleanField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val); + void (JNICALL *SetByteField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val); + void (JNICALL *SetCharField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val); + void (JNICALL *SetShortField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val); + void (JNICALL *SetIntField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jint val); + void (JNICALL *SetLongField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val); + void (JNICALL *SetFloatField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val); + void (JNICALL *SetDoubleField) + (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val); + + jmethodID (JNICALL *GetStaticMethodID) + (JNIEnv *env, jclass clazz, const char *name, const char *sig); + + jobject (JNICALL *CallStaticObjectMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jobject (JNICALL *CallStaticObjectMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jobject (JNICALL *CallStaticObjectMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jboolean (JNICALL *CallStaticBooleanMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jboolean (JNICALL *CallStaticBooleanMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jboolean (JNICALL *CallStaticBooleanMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jbyte (JNICALL *CallStaticByteMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jbyte (JNICALL *CallStaticByteMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jbyte (JNICALL *CallStaticByteMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jchar (JNICALL *CallStaticCharMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jchar (JNICALL *CallStaticCharMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jchar (JNICALL *CallStaticCharMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jshort (JNICALL *CallStaticShortMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jshort (JNICALL *CallStaticShortMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jshort (JNICALL *CallStaticShortMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jint (JNICALL *CallStaticIntMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jint (JNICALL *CallStaticIntMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jint (JNICALL *CallStaticIntMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jlong (JNICALL *CallStaticLongMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jlong (JNICALL *CallStaticLongMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jlong (JNICALL *CallStaticLongMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jfloat (JNICALL *CallStaticFloatMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jfloat (JNICALL *CallStaticFloatMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jfloat (JNICALL *CallStaticFloatMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + jdouble (JNICALL *CallStaticDoubleMethod) + (JNIEnv *env, jclass clazz, jmethodID methodID, ...); + jdouble (JNICALL *CallStaticDoubleMethodV) + (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args); + jdouble (JNICALL *CallStaticDoubleMethodA) + (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args); + + void (JNICALL *CallStaticVoidMethod) + (JNIEnv *env, jclass cls, jmethodID methodID, ...); + void (JNICALL *CallStaticVoidMethodV) + (JNIEnv *env, jclass cls, jmethodID methodID, va_list args); + void (JNICALL *CallStaticVoidMethodA) + (JNIEnv *env, jclass cls, jmethodID methodID, const jvalue * args); + + jfieldID (JNICALL *GetStaticFieldID) + (JNIEnv *env, jclass clazz, const char *name, const char *sig); + jobject (JNICALL *GetStaticObjectField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jboolean (JNICALL *GetStaticBooleanField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jbyte (JNICALL *GetStaticByteField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jchar (JNICALL *GetStaticCharField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jshort (JNICALL *GetStaticShortField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jint (JNICALL *GetStaticIntField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jlong (JNICALL *GetStaticLongField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jfloat (JNICALL *GetStaticFloatField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + jdouble (JNICALL *GetStaticDoubleField) + (JNIEnv *env, jclass clazz, jfieldID fieldID); + + void (JNICALL *SetStaticObjectField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value); + void (JNICALL *SetStaticBooleanField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value); + void (JNICALL *SetStaticByteField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value); + void (JNICALL *SetStaticCharField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value); + void (JNICALL *SetStaticShortField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value); + void (JNICALL *SetStaticIntField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value); + void (JNICALL *SetStaticLongField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value); + void (JNICALL *SetStaticFloatField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value); + void (JNICALL *SetStaticDoubleField) + (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value); + + jstring (JNICALL *NewString) + (JNIEnv *env, const jchar *unicode, jsize len); + jsize (JNICALL *GetStringLength) + (JNIEnv *env, jstring str); + const jchar *(JNICALL *GetStringChars) + (JNIEnv *env, jstring str, jboolean *isCopy); + void (JNICALL *ReleaseStringChars) + (JNIEnv *env, jstring str, const jchar *chars); + + jstring (JNICALL *NewStringUTF) + (JNIEnv *env, const char *utf); + jsize (JNICALL *GetStringUTFLength) + (JNIEnv *env, jstring str); + const char* (JNICALL *GetStringUTFChars) + (JNIEnv *env, jstring str, jboolean *isCopy); + void (JNICALL *ReleaseStringUTFChars) + (JNIEnv *env, jstring str, const char* chars); + + + jsize (JNICALL *GetArrayLength) + (JNIEnv *env, jarray array); + + jobjectArray (JNICALL *NewObjectArray) + (JNIEnv *env, jsize len, jclass clazz, jobject init); + jobject (JNICALL *GetObjectArrayElement) + (JNIEnv *env, jobjectArray array, jsize index); + void (JNICALL *SetObjectArrayElement) + (JNIEnv *env, jobjectArray array, jsize index, jobject val); + + jbooleanArray (JNICALL *NewBooleanArray) + (JNIEnv *env, jsize len); + jbyteArray (JNICALL *NewByteArray) + (JNIEnv *env, jsize len); + jcharArray (JNICALL *NewCharArray) + (JNIEnv *env, jsize len); + jshortArray (JNICALL *NewShortArray) + (JNIEnv *env, jsize len); + jintArray (JNICALL *NewIntArray) + (JNIEnv *env, jsize len); + jlongArray (JNICALL *NewLongArray) + (JNIEnv *env, jsize len); + jfloatArray (JNICALL *NewFloatArray) + (JNIEnv *env, jsize len); + jdoubleArray (JNICALL *NewDoubleArray) + (JNIEnv *env, jsize len); + + jboolean * (JNICALL *GetBooleanArrayElements) + (JNIEnv *env, jbooleanArray array, jboolean *isCopy); + jbyte * (JNICALL *GetByteArrayElements) + (JNIEnv *env, jbyteArray array, jboolean *isCopy); + jchar * (JNICALL *GetCharArrayElements) + (JNIEnv *env, jcharArray array, jboolean *isCopy); + jshort * (JNICALL *GetShortArrayElements) + (JNIEnv *env, jshortArray array, jboolean *isCopy); + jint * (JNICALL *GetIntArrayElements) + (JNIEnv *env, jintArray array, jboolean *isCopy); + jlong * (JNICALL *GetLongArrayElements) + (JNIEnv *env, jlongArray array, jboolean *isCopy); + jfloat * (JNICALL *GetFloatArrayElements) + (JNIEnv *env, jfloatArray array, jboolean *isCopy); + jdouble * (JNICALL *GetDoubleArrayElements) + (JNIEnv *env, jdoubleArray array, jboolean *isCopy); + + void (JNICALL *ReleaseBooleanArrayElements) + (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode); + void (JNICALL *ReleaseByteArrayElements) + (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode); + void (JNICALL *ReleaseCharArrayElements) + (JNIEnv *env, jcharArray array, jchar *elems, jint mode); + void (JNICALL *ReleaseShortArrayElements) + (JNIEnv *env, jshortArray array, jshort *elems, jint mode); + void (JNICALL *ReleaseIntArrayElements) + (JNIEnv *env, jintArray array, jint *elems, jint mode); + void (JNICALL *ReleaseLongArrayElements) + (JNIEnv *env, jlongArray array, jlong *elems, jint mode); + void (JNICALL *ReleaseFloatArrayElements) + (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode); + void (JNICALL *ReleaseDoubleArrayElements) + (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode); + + void (JNICALL *GetBooleanArrayRegion) + (JNIEnv *env, jbooleanArray array, jsize start, jsize l, jboolean *buf); + void (JNICALL *GetByteArrayRegion) + (JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf); + void (JNICALL *GetCharArrayRegion) + (JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf); + void (JNICALL *GetShortArrayRegion) + (JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf); + void (JNICALL *GetIntArrayRegion) + (JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf); + void (JNICALL *GetLongArrayRegion) + (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf); + void (JNICALL *GetFloatArrayRegion) + (JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf); + void (JNICALL *GetDoubleArrayRegion) + (JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf); + + void (JNICALL *SetBooleanArrayRegion) + (JNIEnv *env, jbooleanArray array, jsize start, jsize l, const jboolean *buf); + void (JNICALL *SetByteArrayRegion) + (JNIEnv *env, jbyteArray array, jsize start, jsize len, const jbyte *buf); + void (JNICALL *SetCharArrayRegion) + (JNIEnv *env, jcharArray array, jsize start, jsize len, const jchar *buf); + void (JNICALL *SetShortArrayRegion) + (JNIEnv *env, jshortArray array, jsize start, jsize len, const jshort *buf); + void (JNICALL *SetIntArrayRegion) + (JNIEnv *env, jintArray array, jsize start, jsize len, const jint *buf); + void (JNICALL *SetLongArrayRegion) + (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf); + void (JNICALL *SetFloatArrayRegion) + (JNIEnv *env, jfloatArray array, jsize start, jsize len, const jfloat *buf); + void (JNICALL *SetDoubleArrayRegion) + (JNIEnv *env, jdoubleArray array, jsize start, jsize len, const jdouble *buf); + + jint (JNICALL *RegisterNatives) + (JNIEnv *env, jclass clazz, const JNINativeMethod *methods, + jint nMethods); + jint (JNICALL *UnregisterNatives) + (JNIEnv *env, jclass clazz); + + jint (JNICALL *MonitorEnter) + (JNIEnv *env, jobject obj); + jint (JNICALL *MonitorExit) + (JNIEnv *env, jobject obj); + + jint (JNICALL *GetJavaVM) + (JNIEnv *env, JavaVM **vm); + + void (JNICALL *GetStringRegion) + (JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf); + void (JNICALL *GetStringUTFRegion) + (JNIEnv *env, jstring str, jsize start, jsize len, char *buf); + + void * (JNICALL *GetPrimitiveArrayCritical) + (JNIEnv *env, jarray array, jboolean *isCopy); + void (JNICALL *ReleasePrimitiveArrayCritical) + (JNIEnv *env, jarray array, void *carray, jint mode); + + const jchar * (JNICALL *GetStringCritical) + (JNIEnv *env, jstring string, jboolean *isCopy); + void (JNICALL *ReleaseStringCritical) + (JNIEnv *env, jstring string, const jchar *cstring); + + jweak (JNICALL *NewWeakGlobalRef) + (JNIEnv *env, jobject obj); + void (JNICALL *DeleteWeakGlobalRef) + (JNIEnv *env, jweak ref); + + jboolean (JNICALL *ExceptionCheck) + (JNIEnv *env); + + jobject (JNICALL *NewDirectByteBuffer) + (JNIEnv* env, void* address, jlong capacity); + void* (JNICALL *GetDirectBufferAddress) + (JNIEnv* env, jobject buf); + jlong (JNICALL *GetDirectBufferCapacity) + (JNIEnv* env, jobject buf); + + /* New JNI 1.6 Features */ + + jobjectRefType (JNICALL *GetObjectRefType) + (JNIEnv* env, jobject obj); +}; + +/* + * We use inlined functions for C++ so that programmers can write: + * + * env->FindClass("java/lang/String") + * + * in C++ rather than: + * + * (*env)->FindClass(env, "java/lang/String") + * + * in C. + */ + +struct JNIEnv_ { + const struct JNINativeInterface_ *functions; +#ifdef __cplusplus + + jint GetVersion() { + return functions->GetVersion(this); + } + jclass DefineClass(const char *name, jobject loader, const jbyte *buf, + jsize len) { + return functions->DefineClass(this, name, loader, buf, len); + } + jclass FindClass(const char *name) { + return functions->FindClass(this, name); + } + jmethodID FromReflectedMethod(jobject method) { + return functions->FromReflectedMethod(this,method); + } + jfieldID FromReflectedField(jobject field) { + return functions->FromReflectedField(this,field); + } + + jobject ToReflectedMethod(jclass cls, jmethodID methodID, jboolean isStatic) { + return functions->ToReflectedMethod(this, cls, methodID, isStatic); + } + + jclass GetSuperclass(jclass sub) { + return functions->GetSuperclass(this, sub); + } + jboolean IsAssignableFrom(jclass sub, jclass sup) { + return functions->IsAssignableFrom(this, sub, sup); + } + + jobject ToReflectedField(jclass cls, jfieldID fieldID, jboolean isStatic) { + return functions->ToReflectedField(this,cls,fieldID,isStatic); + } + + jint Throw(jthrowable obj) { + return functions->Throw(this, obj); + } + jint ThrowNew(jclass clazz, const char *msg) { + return functions->ThrowNew(this, clazz, msg); + } + jthrowable ExceptionOccurred() { + return functions->ExceptionOccurred(this); + } + void ExceptionDescribe() { + functions->ExceptionDescribe(this); + } + void ExceptionClear() { + functions->ExceptionClear(this); + } + void FatalError(const char *msg) { + functions->FatalError(this, msg); + } + + jint PushLocalFrame(jint capacity) { + return functions->PushLocalFrame(this,capacity); + } + jobject PopLocalFrame(jobject result) { + return functions->PopLocalFrame(this,result); + } + + jobject NewGlobalRef(jobject lobj) { + return functions->NewGlobalRef(this,lobj); + } + void DeleteGlobalRef(jobject gref) { + functions->DeleteGlobalRef(this,gref); + } + void DeleteLocalRef(jobject obj) { + functions->DeleteLocalRef(this, obj); + } + + jboolean IsSameObject(jobject obj1, jobject obj2) { + return functions->IsSameObject(this,obj1,obj2); + } + + jobject NewLocalRef(jobject ref) { + return functions->NewLocalRef(this,ref); + } + jint EnsureLocalCapacity(jint capacity) { + return functions->EnsureLocalCapacity(this,capacity); + } + + jobject AllocObject(jclass clazz) { + return functions->AllocObject(this,clazz); + } + jobject NewObject(jclass clazz, jmethodID methodID, ...) { + va_list args; + jobject result; + va_start(args, methodID); + result = functions->NewObjectV(this,clazz,methodID,args); + va_end(args); + return result; + } + jobject NewObjectV(jclass clazz, jmethodID methodID, + va_list args) { + return functions->NewObjectV(this,clazz,methodID,args); + } + jobject NewObjectA(jclass clazz, jmethodID methodID, + const jvalue *args) { + return functions->NewObjectA(this,clazz,methodID,args); + } + + jclass GetObjectClass(jobject obj) { + return functions->GetObjectClass(this,obj); + } + jboolean IsInstanceOf(jobject obj, jclass clazz) { + return functions->IsInstanceOf(this,obj,clazz); + } + + jmethodID GetMethodID(jclass clazz, const char *name, + const char *sig) { + return functions->GetMethodID(this,clazz,name,sig); + } + + jobject CallObjectMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jobject result; + va_start(args,methodID); + result = functions->CallObjectMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jobject CallObjectMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallObjectMethodV(this,obj,methodID,args); + } + jobject CallObjectMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallObjectMethodA(this,obj,methodID,args); + } + + jboolean CallBooleanMethod(jobject obj, + jmethodID methodID, ...) { + va_list args; + jboolean result; + va_start(args,methodID); + result = functions->CallBooleanMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jboolean CallBooleanMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallBooleanMethodV(this,obj,methodID,args); + } + jboolean CallBooleanMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallBooleanMethodA(this,obj,methodID, args); + } + + jbyte CallByteMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jbyte result; + va_start(args,methodID); + result = functions->CallByteMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jbyte CallByteMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallByteMethodV(this,obj,methodID,args); + } + jbyte CallByteMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallByteMethodA(this,obj,methodID,args); + } + + jchar CallCharMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jchar result; + va_start(args,methodID); + result = functions->CallCharMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jchar CallCharMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallCharMethodV(this,obj,methodID,args); + } + jchar CallCharMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallCharMethodA(this,obj,methodID,args); + } + + jshort CallShortMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jshort result; + va_start(args,methodID); + result = functions->CallShortMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jshort CallShortMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallShortMethodV(this,obj,methodID,args); + } + jshort CallShortMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallShortMethodA(this,obj,methodID,args); + } + + jint CallIntMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jint result; + va_start(args,methodID); + result = functions->CallIntMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jint CallIntMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallIntMethodV(this,obj,methodID,args); + } + jint CallIntMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallIntMethodA(this,obj,methodID,args); + } + + jlong CallLongMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jlong result; + va_start(args,methodID); + result = functions->CallLongMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jlong CallLongMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallLongMethodV(this,obj,methodID,args); + } + jlong CallLongMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallLongMethodA(this,obj,methodID,args); + } + + jfloat CallFloatMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jfloat result; + va_start(args,methodID); + result = functions->CallFloatMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jfloat CallFloatMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallFloatMethodV(this,obj,methodID,args); + } + jfloat CallFloatMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallFloatMethodA(this,obj,methodID,args); + } + + jdouble CallDoubleMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + jdouble result; + va_start(args,methodID); + result = functions->CallDoubleMethodV(this,obj,methodID,args); + va_end(args); + return result; + } + jdouble CallDoubleMethodV(jobject obj, jmethodID methodID, + va_list args) { + return functions->CallDoubleMethodV(this,obj,methodID,args); + } + jdouble CallDoubleMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + return functions->CallDoubleMethodA(this,obj,methodID,args); + } + + void CallVoidMethod(jobject obj, jmethodID methodID, ...) { + va_list args; + va_start(args,methodID); + functions->CallVoidMethodV(this,obj,methodID,args); + va_end(args); + } + void CallVoidMethodV(jobject obj, jmethodID methodID, + va_list args) { + functions->CallVoidMethodV(this,obj,methodID,args); + } + void CallVoidMethodA(jobject obj, jmethodID methodID, + const jvalue * args) { + functions->CallVoidMethodA(this,obj,methodID,args); + } + + jobject CallNonvirtualObjectMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jobject result; + va_start(args,methodID); + result = functions->CallNonvirtualObjectMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jobject CallNonvirtualObjectMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualObjectMethodV(this,obj,clazz, + methodID,args); + } + jobject CallNonvirtualObjectMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualObjectMethodA(this,obj,clazz, + methodID,args); + } + + jboolean CallNonvirtualBooleanMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jboolean result; + va_start(args,methodID); + result = functions->CallNonvirtualBooleanMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jboolean CallNonvirtualBooleanMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualBooleanMethodV(this,obj,clazz, + methodID,args); + } + jboolean CallNonvirtualBooleanMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualBooleanMethodA(this,obj,clazz, + methodID, args); + } + + jbyte CallNonvirtualByteMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jbyte result; + va_start(args,methodID); + result = functions->CallNonvirtualByteMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jbyte CallNonvirtualByteMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualByteMethodV(this,obj,clazz, + methodID,args); + } + jbyte CallNonvirtualByteMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualByteMethodA(this,obj,clazz, + methodID,args); + } + + jchar CallNonvirtualCharMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jchar result; + va_start(args,methodID); + result = functions->CallNonvirtualCharMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jchar CallNonvirtualCharMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualCharMethodV(this,obj,clazz, + methodID,args); + } + jchar CallNonvirtualCharMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualCharMethodA(this,obj,clazz, + methodID,args); + } + + jshort CallNonvirtualShortMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jshort result; + va_start(args,methodID); + result = functions->CallNonvirtualShortMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jshort CallNonvirtualShortMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualShortMethodV(this,obj,clazz, + methodID,args); + } + jshort CallNonvirtualShortMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualShortMethodA(this,obj,clazz, + methodID,args); + } + + jint CallNonvirtualIntMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jint result; + va_start(args,methodID); + result = functions->CallNonvirtualIntMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jint CallNonvirtualIntMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualIntMethodV(this,obj,clazz, + methodID,args); + } + jint CallNonvirtualIntMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualIntMethodA(this,obj,clazz, + methodID,args); + } + + jlong CallNonvirtualLongMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jlong result; + va_start(args,methodID); + result = functions->CallNonvirtualLongMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallNonvirtualLongMethodV(this,obj,clazz, + methodID,args); + } + jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz, + jmethodID methodID, const jvalue * args) { + return functions->CallNonvirtualLongMethodA(this,obj,clazz, + methodID,args); + } + + jfloat CallNonvirtualFloatMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jfloat result; + va_start(args,methodID); + result = functions->CallNonvirtualFloatMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jfloat CallNonvirtualFloatMethodV(jobject obj, jclass clazz, + jmethodID methodID, + va_list args) { + return functions->CallNonvirtualFloatMethodV(this,obj,clazz, + methodID,args); + } + jfloat CallNonvirtualFloatMethodA(jobject obj, jclass clazz, + jmethodID methodID, + const jvalue * args) { + return functions->CallNonvirtualFloatMethodA(this,obj,clazz, + methodID,args); + } + + jdouble CallNonvirtualDoubleMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + jdouble result; + va_start(args,methodID); + result = functions->CallNonvirtualDoubleMethodV(this,obj,clazz, + methodID,args); + va_end(args); + return result; + } + jdouble CallNonvirtualDoubleMethodV(jobject obj, jclass clazz, + jmethodID methodID, + va_list args) { + return functions->CallNonvirtualDoubleMethodV(this,obj,clazz, + methodID,args); + } + jdouble CallNonvirtualDoubleMethodA(jobject obj, jclass clazz, + jmethodID methodID, + const jvalue * args) { + return functions->CallNonvirtualDoubleMethodA(this,obj,clazz, + methodID,args); + } + + void CallNonvirtualVoidMethod(jobject obj, jclass clazz, + jmethodID methodID, ...) { + va_list args; + va_start(args,methodID); + functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args); + va_end(args); + } + void CallNonvirtualVoidMethodV(jobject obj, jclass clazz, + jmethodID methodID, + va_list args) { + functions->CallNonvirtualVoidMethodV(this,obj,clazz,methodID,args); + } + void CallNonvirtualVoidMethodA(jobject obj, jclass clazz, + jmethodID methodID, + const jvalue * args) { + functions->CallNonvirtualVoidMethodA(this,obj,clazz,methodID,args); + } + + jfieldID GetFieldID(jclass clazz, const char *name, + const char *sig) { + return functions->GetFieldID(this,clazz,name,sig); + } + + jobject GetObjectField(jobject obj, jfieldID fieldID) { + return functions->GetObjectField(this,obj,fieldID); + } + jboolean GetBooleanField(jobject obj, jfieldID fieldID) { + return functions->GetBooleanField(this,obj,fieldID); + } + jbyte GetByteField(jobject obj, jfieldID fieldID) { + return functions->GetByteField(this,obj,fieldID); + } + jchar GetCharField(jobject obj, jfieldID fieldID) { + return functions->GetCharField(this,obj,fieldID); + } + jshort GetShortField(jobject obj, jfieldID fieldID) { + return functions->GetShortField(this,obj,fieldID); + } + jint GetIntField(jobject obj, jfieldID fieldID) { + return functions->GetIntField(this,obj,fieldID); + } + jlong GetLongField(jobject obj, jfieldID fieldID) { + return functions->GetLongField(this,obj,fieldID); + } + jfloat GetFloatField(jobject obj, jfieldID fieldID) { + return functions->GetFloatField(this,obj,fieldID); + } + jdouble GetDoubleField(jobject obj, jfieldID fieldID) { + return functions->GetDoubleField(this,obj,fieldID); + } + + void SetObjectField(jobject obj, jfieldID fieldID, jobject val) { + functions->SetObjectField(this,obj,fieldID,val); + } + void SetBooleanField(jobject obj, jfieldID fieldID, + jboolean val) { + functions->SetBooleanField(this,obj,fieldID,val); + } + void SetByteField(jobject obj, jfieldID fieldID, + jbyte val) { + functions->SetByteField(this,obj,fieldID,val); + } + void SetCharField(jobject obj, jfieldID fieldID, + jchar val) { + functions->SetCharField(this,obj,fieldID,val); + } + void SetShortField(jobject obj, jfieldID fieldID, + jshort val) { + functions->SetShortField(this,obj,fieldID,val); + } + void SetIntField(jobject obj, jfieldID fieldID, + jint val) { + functions->SetIntField(this,obj,fieldID,val); + } + void SetLongField(jobject obj, jfieldID fieldID, + jlong val) { + functions->SetLongField(this,obj,fieldID,val); + } + void SetFloatField(jobject obj, jfieldID fieldID, + jfloat val) { + functions->SetFloatField(this,obj,fieldID,val); + } + void SetDoubleField(jobject obj, jfieldID fieldID, + jdouble val) { + functions->SetDoubleField(this,obj,fieldID,val); + } + + jmethodID GetStaticMethodID(jclass clazz, const char *name, + const char *sig) { + return functions->GetStaticMethodID(this,clazz,name,sig); + } + + jobject CallStaticObjectMethod(jclass clazz, jmethodID methodID, + ...) { + va_list args; + jobject result; + va_start(args,methodID); + result = functions->CallStaticObjectMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jobject CallStaticObjectMethodV(jclass clazz, jmethodID methodID, + va_list args) { + return functions->CallStaticObjectMethodV(this,clazz,methodID,args); + } + jobject CallStaticObjectMethodA(jclass clazz, jmethodID methodID, + const jvalue *args) { + return functions->CallStaticObjectMethodA(this,clazz,methodID,args); + } + + jboolean CallStaticBooleanMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jboolean result; + va_start(args,methodID); + result = functions->CallStaticBooleanMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jboolean CallStaticBooleanMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticBooleanMethodV(this,clazz,methodID,args); + } + jboolean CallStaticBooleanMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticBooleanMethodA(this,clazz,methodID,args); + } + + jbyte CallStaticByteMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jbyte result; + va_start(args,methodID); + result = functions->CallStaticByteMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jbyte CallStaticByteMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticByteMethodV(this,clazz,methodID,args); + } + jbyte CallStaticByteMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticByteMethodA(this,clazz,methodID,args); + } + + jchar CallStaticCharMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jchar result; + va_start(args,methodID); + result = functions->CallStaticCharMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jchar CallStaticCharMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticCharMethodV(this,clazz,methodID,args); + } + jchar CallStaticCharMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticCharMethodA(this,clazz,methodID,args); + } + + jshort CallStaticShortMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jshort result; + va_start(args,methodID); + result = functions->CallStaticShortMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jshort CallStaticShortMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticShortMethodV(this,clazz,methodID,args); + } + jshort CallStaticShortMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticShortMethodA(this,clazz,methodID,args); + } + + jint CallStaticIntMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jint result; + va_start(args,methodID); + result = functions->CallStaticIntMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jint CallStaticIntMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticIntMethodV(this,clazz,methodID,args); + } + jint CallStaticIntMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticIntMethodA(this,clazz,methodID,args); + } + + jlong CallStaticLongMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jlong result; + va_start(args,methodID); + result = functions->CallStaticLongMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jlong CallStaticLongMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticLongMethodV(this,clazz,methodID,args); + } + jlong CallStaticLongMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticLongMethodA(this,clazz,methodID,args); + } + + jfloat CallStaticFloatMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jfloat result; + va_start(args,methodID); + result = functions->CallStaticFloatMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jfloat CallStaticFloatMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticFloatMethodV(this,clazz,methodID,args); + } + jfloat CallStaticFloatMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticFloatMethodA(this,clazz,methodID,args); + } + + jdouble CallStaticDoubleMethod(jclass clazz, + jmethodID methodID, ...) { + va_list args; + jdouble result; + va_start(args,methodID); + result = functions->CallStaticDoubleMethodV(this,clazz,methodID,args); + va_end(args); + return result; + } + jdouble CallStaticDoubleMethodV(jclass clazz, + jmethodID methodID, va_list args) { + return functions->CallStaticDoubleMethodV(this,clazz,methodID,args); + } + jdouble CallStaticDoubleMethodA(jclass clazz, + jmethodID methodID, const jvalue *args) { + return functions->CallStaticDoubleMethodA(this,clazz,methodID,args); + } + + void CallStaticVoidMethod(jclass cls, jmethodID methodID, ...) { + va_list args; + va_start(args,methodID); + functions->CallStaticVoidMethodV(this,cls,methodID,args); + va_end(args); + } + void CallStaticVoidMethodV(jclass cls, jmethodID methodID, + va_list args) { + functions->CallStaticVoidMethodV(this,cls,methodID,args); + } + void CallStaticVoidMethodA(jclass cls, jmethodID methodID, + const jvalue * args) { + functions->CallStaticVoidMethodA(this,cls,methodID,args); + } + + jfieldID GetStaticFieldID(jclass clazz, const char *name, + const char *sig) { + return functions->GetStaticFieldID(this,clazz,name,sig); + } + jobject GetStaticObjectField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticObjectField(this,clazz,fieldID); + } + jboolean GetStaticBooleanField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticBooleanField(this,clazz,fieldID); + } + jbyte GetStaticByteField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticByteField(this,clazz,fieldID); + } + jchar GetStaticCharField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticCharField(this,clazz,fieldID); + } + jshort GetStaticShortField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticShortField(this,clazz,fieldID); + } + jint GetStaticIntField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticIntField(this,clazz,fieldID); + } + jlong GetStaticLongField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticLongField(this,clazz,fieldID); + } + jfloat GetStaticFloatField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticFloatField(this,clazz,fieldID); + } + jdouble GetStaticDoubleField(jclass clazz, jfieldID fieldID) { + return functions->GetStaticDoubleField(this,clazz,fieldID); + } + + void SetStaticObjectField(jclass clazz, jfieldID fieldID, + jobject value) { + functions->SetStaticObjectField(this,clazz,fieldID,value); + } + void SetStaticBooleanField(jclass clazz, jfieldID fieldID, + jboolean value) { + functions->SetStaticBooleanField(this,clazz,fieldID,value); + } + void SetStaticByteField(jclass clazz, jfieldID fieldID, + jbyte value) { + functions->SetStaticByteField(this,clazz,fieldID,value); + } + void SetStaticCharField(jclass clazz, jfieldID fieldID, + jchar value) { + functions->SetStaticCharField(this,clazz,fieldID,value); + } + void SetStaticShortField(jclass clazz, jfieldID fieldID, + jshort value) { + functions->SetStaticShortField(this,clazz,fieldID,value); + } + void SetStaticIntField(jclass clazz, jfieldID fieldID, + jint value) { + functions->SetStaticIntField(this,clazz,fieldID,value); + } + void SetStaticLongField(jclass clazz, jfieldID fieldID, + jlong value) { + functions->SetStaticLongField(this,clazz,fieldID,value); + } + void SetStaticFloatField(jclass clazz, jfieldID fieldID, + jfloat value) { + functions->SetStaticFloatField(this,clazz,fieldID,value); + } + void SetStaticDoubleField(jclass clazz, jfieldID fieldID, + jdouble value) { + functions->SetStaticDoubleField(this,clazz,fieldID,value); + } + + jstring NewString(const jchar *unicode, jsize len) { + return functions->NewString(this,unicode,len); + } + jsize GetStringLength(jstring str) { + return functions->GetStringLength(this,str); + } + const jchar *GetStringChars(jstring str, jboolean *isCopy) { + return functions->GetStringChars(this,str,isCopy); + } + void ReleaseStringChars(jstring str, const jchar *chars) { + functions->ReleaseStringChars(this,str,chars); + } + + jstring NewStringUTF(const char *utf) { + return functions->NewStringUTF(this,utf); + } + jsize GetStringUTFLength(jstring str) { + return functions->GetStringUTFLength(this,str); + } + const char* GetStringUTFChars(jstring str, jboolean *isCopy) { + return functions->GetStringUTFChars(this,str,isCopy); + } + void ReleaseStringUTFChars(jstring str, const char* chars) { + functions->ReleaseStringUTFChars(this,str,chars); + } + + jsize GetArrayLength(jarray array) { + return functions->GetArrayLength(this,array); + } + + jobjectArray NewObjectArray(jsize len, jclass clazz, + jobject init) { + return functions->NewObjectArray(this,len,clazz,init); + } + jobject GetObjectArrayElement(jobjectArray array, jsize index) { + return functions->GetObjectArrayElement(this,array,index); + } + void SetObjectArrayElement(jobjectArray array, jsize index, + jobject val) { + functions->SetObjectArrayElement(this,array,index,val); + } + + jbooleanArray NewBooleanArray(jsize len) { + return functions->NewBooleanArray(this,len); + } + jbyteArray NewByteArray(jsize len) { + return functions->NewByteArray(this,len); + } + jcharArray NewCharArray(jsize len) { + return functions->NewCharArray(this,len); + } + jshortArray NewShortArray(jsize len) { + return functions->NewShortArray(this,len); + } + jintArray NewIntArray(jsize len) { + return functions->NewIntArray(this,len); + } + jlongArray NewLongArray(jsize len) { + return functions->NewLongArray(this,len); + } + jfloatArray NewFloatArray(jsize len) { + return functions->NewFloatArray(this,len); + } + jdoubleArray NewDoubleArray(jsize len) { + return functions->NewDoubleArray(this,len); + } + + jboolean * GetBooleanArrayElements(jbooleanArray array, jboolean *isCopy) { + return functions->GetBooleanArrayElements(this,array,isCopy); + } + jbyte * GetByteArrayElements(jbyteArray array, jboolean *isCopy) { + return functions->GetByteArrayElements(this,array,isCopy); + } + jchar * GetCharArrayElements(jcharArray array, jboolean *isCopy) { + return functions->GetCharArrayElements(this,array,isCopy); + } + jshort * GetShortArrayElements(jshortArray array, jboolean *isCopy) { + return functions->GetShortArrayElements(this,array,isCopy); + } + jint * GetIntArrayElements(jintArray array, jboolean *isCopy) { + return functions->GetIntArrayElements(this,array,isCopy); + } + jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) { + return functions->GetLongArrayElements(this,array,isCopy); + } + jfloat * GetFloatArrayElements(jfloatArray array, jboolean *isCopy) { + return functions->GetFloatArrayElements(this,array,isCopy); + } + jdouble * GetDoubleArrayElements(jdoubleArray array, jboolean *isCopy) { + return functions->GetDoubleArrayElements(this,array,isCopy); + } + + void ReleaseBooleanArrayElements(jbooleanArray array, + jboolean *elems, + jint mode) { + functions->ReleaseBooleanArrayElements(this,array,elems,mode); + } + void ReleaseByteArrayElements(jbyteArray array, + jbyte *elems, + jint mode) { + functions->ReleaseByteArrayElements(this,array,elems,mode); + } + void ReleaseCharArrayElements(jcharArray array, + jchar *elems, + jint mode) { + functions->ReleaseCharArrayElements(this,array,elems,mode); + } + void ReleaseShortArrayElements(jshortArray array, + jshort *elems, + jint mode) { + functions->ReleaseShortArrayElements(this,array,elems,mode); + } + void ReleaseIntArrayElements(jintArray array, + jint *elems, + jint mode) { + functions->ReleaseIntArrayElements(this,array,elems,mode); + } + void ReleaseLongArrayElements(jlongArray array, + jlong *elems, + jint mode) { + functions->ReleaseLongArrayElements(this,array,elems,mode); + } + void ReleaseFloatArrayElements(jfloatArray array, + jfloat *elems, + jint mode) { + functions->ReleaseFloatArrayElements(this,array,elems,mode); + } + void ReleaseDoubleArrayElements(jdoubleArray array, + jdouble *elems, + jint mode) { + functions->ReleaseDoubleArrayElements(this,array,elems,mode); + } + + void GetBooleanArrayRegion(jbooleanArray array, + jsize start, jsize len, jboolean *buf) { + functions->GetBooleanArrayRegion(this,array,start,len,buf); + } + void GetByteArrayRegion(jbyteArray array, + jsize start, jsize len, jbyte *buf) { + functions->GetByteArrayRegion(this,array,start,len,buf); + } + void GetCharArrayRegion(jcharArray array, + jsize start, jsize len, jchar *buf) { + functions->GetCharArrayRegion(this,array,start,len,buf); + } + void GetShortArrayRegion(jshortArray array, + jsize start, jsize len, jshort *buf) { + functions->GetShortArrayRegion(this,array,start,len,buf); + } + void GetIntArrayRegion(jintArray array, + jsize start, jsize len, jint *buf) { + functions->GetIntArrayRegion(this,array,start,len,buf); + } + void GetLongArrayRegion(jlongArray array, + jsize start, jsize len, jlong *buf) { + functions->GetLongArrayRegion(this,array,start,len,buf); + } + void GetFloatArrayRegion(jfloatArray array, + jsize start, jsize len, jfloat *buf) { + functions->GetFloatArrayRegion(this,array,start,len,buf); + } + void GetDoubleArrayRegion(jdoubleArray array, + jsize start, jsize len, jdouble *buf) { + functions->GetDoubleArrayRegion(this,array,start,len,buf); + } + + void SetBooleanArrayRegion(jbooleanArray array, jsize start, jsize len, + const jboolean *buf) { + functions->SetBooleanArrayRegion(this,array,start,len,buf); + } + void SetByteArrayRegion(jbyteArray array, jsize start, jsize len, + const jbyte *buf) { + functions->SetByteArrayRegion(this,array,start,len,buf); + } + void SetCharArrayRegion(jcharArray array, jsize start, jsize len, + const jchar *buf) { + functions->SetCharArrayRegion(this,array,start,len,buf); + } + void SetShortArrayRegion(jshortArray array, jsize start, jsize len, + const jshort *buf) { + functions->SetShortArrayRegion(this,array,start,len,buf); + } + void SetIntArrayRegion(jintArray array, jsize start, jsize len, + const jint *buf) { + functions->SetIntArrayRegion(this,array,start,len,buf); + } + void SetLongArrayRegion(jlongArray array, jsize start, jsize len, + const jlong *buf) { + functions->SetLongArrayRegion(this,array,start,len,buf); + } + void SetFloatArrayRegion(jfloatArray array, jsize start, jsize len, + const jfloat *buf) { + functions->SetFloatArrayRegion(this,array,start,len,buf); + } + void SetDoubleArrayRegion(jdoubleArray array, jsize start, jsize len, + const jdouble *buf) { + functions->SetDoubleArrayRegion(this,array,start,len,buf); + } + + jint RegisterNatives(jclass clazz, const JNINativeMethod *methods, + jint nMethods) { + return functions->RegisterNatives(this,clazz,methods,nMethods); + } + jint UnregisterNatives(jclass clazz) { + return functions->UnregisterNatives(this,clazz); + } + + jint MonitorEnter(jobject obj) { + return functions->MonitorEnter(this,obj); + } + jint MonitorExit(jobject obj) { + return functions->MonitorExit(this,obj); + } + + jint GetJavaVM(JavaVM **vm) { + return functions->GetJavaVM(this,vm); + } + + void GetStringRegion(jstring str, jsize start, jsize len, jchar *buf) { + functions->GetStringRegion(this,str,start,len,buf); + } + void GetStringUTFRegion(jstring str, jsize start, jsize len, char *buf) { + functions->GetStringUTFRegion(this,str,start,len,buf); + } + + void * GetPrimitiveArrayCritical(jarray array, jboolean *isCopy) { + return functions->GetPrimitiveArrayCritical(this,array,isCopy); + } + void ReleasePrimitiveArrayCritical(jarray array, void *carray, jint mode) { + functions->ReleasePrimitiveArrayCritical(this,array,carray,mode); + } + + const jchar * GetStringCritical(jstring string, jboolean *isCopy) { + return functions->GetStringCritical(this,string,isCopy); + } + void ReleaseStringCritical(jstring string, const jchar *cstring) { + functions->ReleaseStringCritical(this,string,cstring); + } + + jweak NewWeakGlobalRef(jobject obj) { + return functions->NewWeakGlobalRef(this,obj); + } + void DeleteWeakGlobalRef(jweak ref) { + functions->DeleteWeakGlobalRef(this,ref); + } + + jboolean ExceptionCheck() { + return functions->ExceptionCheck(this); + } + + jobject NewDirectByteBuffer(void* address, jlong capacity) { + return functions->NewDirectByteBuffer(this, address, capacity); + } + void* GetDirectBufferAddress(jobject buf) { + return functions->GetDirectBufferAddress(this, buf); + } + jlong GetDirectBufferCapacity(jobject buf) { + return functions->GetDirectBufferCapacity(this, buf); + } + jobjectRefType GetObjectRefType(jobject obj) { + return functions->GetObjectRefType(this, obj); + } + +#endif /* __cplusplus */ +}; + +typedef struct JavaVMOption { + char *optionString; + void *extraInfo; +} JavaVMOption; + +typedef struct JavaVMInitArgs { + jint version; + + jint nOptions; + JavaVMOption *options; + jboolean ignoreUnrecognized; +} JavaVMInitArgs; + +typedef struct JavaVMAttachArgs { + jint version; + + char *name; + jobject group; +} JavaVMAttachArgs; + +/* These will be VM-specific. */ + +#define JDK1_2 +#define JDK1_4 + +/* End VM-specific. */ + +struct JNIInvokeInterface_ { + void *reserved0; + void *reserved1; + void *reserved2; + + jint (JNICALL *DestroyJavaVM)(JavaVM *vm); + + jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void *args); + + jint (JNICALL *DetachCurrentThread)(JavaVM *vm); + + jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version); + + jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void **penv, void *args); +}; + +struct JavaVM_ { + const struct JNIInvokeInterface_ *functions; +#ifdef __cplusplus + + jint DestroyJavaVM() { + return functions->DestroyJavaVM(this); + } + jint AttachCurrentThread(void **penv, void *args) { + return functions->AttachCurrentThread(this, penv, args); + } + jint DetachCurrentThread() { + return functions->DetachCurrentThread(this); + } + + jint GetEnv(void **penv, jint version) { + return functions->GetEnv(this, penv, version); + } + jint AttachCurrentThreadAsDaemon(void **penv, void *args) { + return functions->AttachCurrentThreadAsDaemon(this, penv, args); + } +#endif +}; + +#ifdef _JNI_IMPLEMENTATION_ +#define _JNI_IMPORT_OR_EXPORT_ JNIEXPORT +#else +#define _JNI_IMPORT_OR_EXPORT_ JNIIMPORT +#endif +_JNI_IMPORT_OR_EXPORT_ jint JNICALL +JNI_GetDefaultJavaVMInitArgs(void *args); + +_JNI_IMPORT_OR_EXPORT_ jint JNICALL +JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args); + +_JNI_IMPORT_OR_EXPORT_ jint JNICALL +JNI_GetCreatedJavaVMs(JavaVM **, jsize, jsize *); + +/* Defined by native libraries. */ +JNIEXPORT jint JNICALL +JNI_OnLoad(JavaVM *vm, void *reserved); + +JNIEXPORT void JNICALL +JNI_OnUnload(JavaVM *vm, void *reserved); + +#define JNI_VERSION_1_1 0x00010001 +#define JNI_VERSION_1_2 0x00010002 +#define JNI_VERSION_1_4 0x00010004 +#define JNI_VERSION_1_6 0x00010006 +#define JNI_VERSION_1_8 0x00010008 + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* !_JAVASOFT_JNI_H_ */ diff --git a/arthas-vmtool/src/main/native/head/jvmti.h b/arthas-vmtool/src/main/native/head/jvmti.h new file mode 100755 index 000000000..74243f540 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/jvmti.h @@ -0,0 +1,2534 @@ +/* + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + + /* AUTOMATICALLY GENERATED FILE - DO NOT EDIT */ + + + /* Include file for the Java(tm) Virtual Machine Tool Interface */ + +#ifndef _JAVA_JVMTI_H_ +#define _JAVA_JVMTI_H_ + +#include "jni.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + JVMTI_VERSION_1 = 0x30010000, + JVMTI_VERSION_1_0 = 0x30010000, + JVMTI_VERSION_1_1 = 0x30010100, + JVMTI_VERSION_1_2 = 0x30010200, + + JVMTI_VERSION = 0x30000000 + (1 * 0x10000) + (2 * 0x100) + 1 /* version: 1.2.1 */ +}; + +JNIEXPORT jint JNICALL +Agent_OnLoad(JavaVM *vm, char *options, void *reserved); + +JNIEXPORT jint JNICALL +Agent_OnAttach(JavaVM* vm, char* options, void* reserved); + +JNIEXPORT void JNICALL +Agent_OnUnload(JavaVM *vm); + + /* Forward declaration of the environment */ + +struct _jvmtiEnv; + +struct jvmtiInterface_1_; + +#ifdef __cplusplus +typedef _jvmtiEnv jvmtiEnv; +#else +typedef const struct jvmtiInterface_1_ *jvmtiEnv; +#endif /* __cplusplus */ + +/* Derived Base Types */ + +typedef jobject jthread; +typedef jobject jthreadGroup; +typedef jlong jlocation; +struct _jrawMonitorID; +typedef struct _jrawMonitorID *jrawMonitorID; +typedef struct JNINativeInterface_ jniNativeInterface; + + /* Constants */ + + + /* Thread State Flags */ + +enum { + JVMTI_THREAD_STATE_ALIVE = 0x0001, + JVMTI_THREAD_STATE_TERMINATED = 0x0002, + JVMTI_THREAD_STATE_RUNNABLE = 0x0004, + JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER = 0x0400, + JVMTI_THREAD_STATE_WAITING = 0x0080, + JVMTI_THREAD_STATE_WAITING_INDEFINITELY = 0x0010, + JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020, + JVMTI_THREAD_STATE_SLEEPING = 0x0040, + JVMTI_THREAD_STATE_IN_OBJECT_WAIT = 0x0100, + JVMTI_THREAD_STATE_PARKED = 0x0200, + JVMTI_THREAD_STATE_SUSPENDED = 0x100000, + JVMTI_THREAD_STATE_INTERRUPTED = 0x200000, + JVMTI_THREAD_STATE_IN_NATIVE = 0x400000, + JVMTI_THREAD_STATE_VENDOR_1 = 0x10000000, + JVMTI_THREAD_STATE_VENDOR_2 = 0x20000000, + JVMTI_THREAD_STATE_VENDOR_3 = 0x40000000 +}; + + /* java.lang.Thread.State Conversion Masks */ + +enum { + JVMTI_JAVA_LANG_THREAD_STATE_MASK = JVMTI_THREAD_STATE_TERMINATED | JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_INDEFINITELY | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT, + JVMTI_JAVA_LANG_THREAD_STATE_NEW = 0, + JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED = JVMTI_THREAD_STATE_TERMINATED, + JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE, + JVMTI_JAVA_LANG_THREAD_STATE_BLOCKED = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER, + JVMTI_JAVA_LANG_THREAD_STATE_WAITING = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_INDEFINITELY, + JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +}; + + /* Thread Priority Constants */ + +enum { + JVMTI_THREAD_MIN_PRIORITY = 1, + JVMTI_THREAD_NORM_PRIORITY = 5, + JVMTI_THREAD_MAX_PRIORITY = 10 +}; + + /* Heap Filter Flags */ + +enum { + JVMTI_HEAP_FILTER_TAGGED = 0x4, + JVMTI_HEAP_FILTER_UNTAGGED = 0x8, + JVMTI_HEAP_FILTER_CLASS_TAGGED = 0x10, + JVMTI_HEAP_FILTER_CLASS_UNTAGGED = 0x20 +}; + + /* Heap Visit Control Flags */ + +enum { + JVMTI_VISIT_OBJECTS = 0x100, + JVMTI_VISIT_ABORT = 0x8000 +}; + + /* Heap Reference Enumeration */ + +typedef enum { + JVMTI_HEAP_REFERENCE_CLASS = 1, + JVMTI_HEAP_REFERENCE_FIELD = 2, + JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT = 3, + JVMTI_HEAP_REFERENCE_CLASS_LOADER = 4, + JVMTI_HEAP_REFERENCE_SIGNERS = 5, + JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN = 6, + JVMTI_HEAP_REFERENCE_INTERFACE = 7, + JVMTI_HEAP_REFERENCE_STATIC_FIELD = 8, + JVMTI_HEAP_REFERENCE_CONSTANT_POOL = 9, + JVMTI_HEAP_REFERENCE_SUPERCLASS = 10, + JVMTI_HEAP_REFERENCE_JNI_GLOBAL = 21, + JVMTI_HEAP_REFERENCE_SYSTEM_CLASS = 22, + JVMTI_HEAP_REFERENCE_MONITOR = 23, + JVMTI_HEAP_REFERENCE_STACK_LOCAL = 24, + JVMTI_HEAP_REFERENCE_JNI_LOCAL = 25, + JVMTI_HEAP_REFERENCE_THREAD = 26, + JVMTI_HEAP_REFERENCE_OTHER = 27 +} jvmtiHeapReferenceKind; + + /* Primitive Type Enumeration */ + +typedef enum { + JVMTI_PRIMITIVE_TYPE_BOOLEAN = 90, + JVMTI_PRIMITIVE_TYPE_BYTE = 66, + JVMTI_PRIMITIVE_TYPE_CHAR = 67, + JVMTI_PRIMITIVE_TYPE_SHORT = 83, + JVMTI_PRIMITIVE_TYPE_INT = 73, + JVMTI_PRIMITIVE_TYPE_LONG = 74, + JVMTI_PRIMITIVE_TYPE_FLOAT = 70, + JVMTI_PRIMITIVE_TYPE_DOUBLE = 68 +} jvmtiPrimitiveType; + + /* Heap Object Filter Enumeration */ + +typedef enum { + JVMTI_HEAP_OBJECT_TAGGED = 1, + JVMTI_HEAP_OBJECT_UNTAGGED = 2, + JVMTI_HEAP_OBJECT_EITHER = 3 +} jvmtiHeapObjectFilter; + + /* Heap Root Kind Enumeration */ + +typedef enum { + JVMTI_HEAP_ROOT_JNI_GLOBAL = 1, + JVMTI_HEAP_ROOT_SYSTEM_CLASS = 2, + JVMTI_HEAP_ROOT_MONITOR = 3, + JVMTI_HEAP_ROOT_STACK_LOCAL = 4, + JVMTI_HEAP_ROOT_JNI_LOCAL = 5, + JVMTI_HEAP_ROOT_THREAD = 6, + JVMTI_HEAP_ROOT_OTHER = 7 +} jvmtiHeapRootKind; + + /* Object Reference Enumeration */ + +typedef enum { + JVMTI_REFERENCE_CLASS = 1, + JVMTI_REFERENCE_FIELD = 2, + JVMTI_REFERENCE_ARRAY_ELEMENT = 3, + JVMTI_REFERENCE_CLASS_LOADER = 4, + JVMTI_REFERENCE_SIGNERS = 5, + JVMTI_REFERENCE_PROTECTION_DOMAIN = 6, + JVMTI_REFERENCE_INTERFACE = 7, + JVMTI_REFERENCE_STATIC_FIELD = 8, + JVMTI_REFERENCE_CONSTANT_POOL = 9 +} jvmtiObjectReferenceKind; + + /* Iteration Control Enumeration */ + +typedef enum { + JVMTI_ITERATION_CONTINUE = 1, + JVMTI_ITERATION_IGNORE = 2, + JVMTI_ITERATION_ABORT = 0 +} jvmtiIterationControl; + + /* Class Status Flags */ + +enum { + JVMTI_CLASS_STATUS_VERIFIED = 1, + JVMTI_CLASS_STATUS_PREPARED = 2, + JVMTI_CLASS_STATUS_INITIALIZED = 4, + JVMTI_CLASS_STATUS_ERROR = 8, + JVMTI_CLASS_STATUS_ARRAY = 16, + JVMTI_CLASS_STATUS_PRIMITIVE = 32 +}; + + /* Event Enable/Disable */ + +typedef enum { + JVMTI_ENABLE = 1, + JVMTI_DISABLE = 0 +} jvmtiEventMode; + + /* Extension Function/Event Parameter Types */ + +typedef enum { + JVMTI_TYPE_JBYTE = 101, + JVMTI_TYPE_JCHAR = 102, + JVMTI_TYPE_JSHORT = 103, + JVMTI_TYPE_JINT = 104, + JVMTI_TYPE_JLONG = 105, + JVMTI_TYPE_JFLOAT = 106, + JVMTI_TYPE_JDOUBLE = 107, + JVMTI_TYPE_JBOOLEAN = 108, + JVMTI_TYPE_JOBJECT = 109, + JVMTI_TYPE_JTHREAD = 110, + JVMTI_TYPE_JCLASS = 111, + JVMTI_TYPE_JVALUE = 112, + JVMTI_TYPE_JFIELDID = 113, + JVMTI_TYPE_JMETHODID = 114, + JVMTI_TYPE_CCHAR = 115, + JVMTI_TYPE_CVOID = 116, + JVMTI_TYPE_JNIENV = 117 +} jvmtiParamTypes; + + /* Extension Function/Event Parameter Kinds */ + +typedef enum { + JVMTI_KIND_IN = 91, + JVMTI_KIND_IN_PTR = 92, + JVMTI_KIND_IN_BUF = 93, + JVMTI_KIND_ALLOC_BUF = 94, + JVMTI_KIND_ALLOC_ALLOC_BUF = 95, + JVMTI_KIND_OUT = 96, + JVMTI_KIND_OUT_BUF = 97 +} jvmtiParamKind; + + /* Timer Kinds */ + +typedef enum { + JVMTI_TIMER_USER_CPU = 30, + JVMTI_TIMER_TOTAL_CPU = 31, + JVMTI_TIMER_ELAPSED = 32 +} jvmtiTimerKind; + + /* Phases of execution */ + +typedef enum { + JVMTI_PHASE_ONLOAD = 1, + JVMTI_PHASE_PRIMORDIAL = 2, + JVMTI_PHASE_START = 6, + JVMTI_PHASE_LIVE = 4, + JVMTI_PHASE_DEAD = 8 +} jvmtiPhase; + + /* Version Interface Types */ + +enum { + JVMTI_VERSION_INTERFACE_JNI = 0x00000000, + JVMTI_VERSION_INTERFACE_JVMTI = 0x30000000 +}; + + /* Version Masks */ + +enum { + JVMTI_VERSION_MASK_INTERFACE_TYPE = 0x70000000, + JVMTI_VERSION_MASK_MAJOR = 0x0FFF0000, + JVMTI_VERSION_MASK_MINOR = 0x0000FF00, + JVMTI_VERSION_MASK_MICRO = 0x000000FF +}; + + /* Version Shifts */ + +enum { + JVMTI_VERSION_SHIFT_MAJOR = 16, + JVMTI_VERSION_SHIFT_MINOR = 8, + JVMTI_VERSION_SHIFT_MICRO = 0 +}; + + /* Verbose Flag Enumeration */ + +typedef enum { + JVMTI_VERBOSE_OTHER = 0, + JVMTI_VERBOSE_GC = 1, + JVMTI_VERBOSE_CLASS = 2, + JVMTI_VERBOSE_JNI = 4 +} jvmtiVerboseFlag; + + /* JLocation Format Enumeration */ + +typedef enum { + JVMTI_JLOCATION_JVMBCI = 1, + JVMTI_JLOCATION_MACHINEPC = 2, + JVMTI_JLOCATION_OTHER = 0 +} jvmtiJlocationFormat; + + /* Resource Exhaustion Flags */ + +enum { + JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR = 0x0001, + JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP = 0x0002, + JVMTI_RESOURCE_EXHAUSTED_THREADS = 0x0004 +}; + + /* Errors */ + +typedef enum { + JVMTI_ERROR_NONE = 0, + JVMTI_ERROR_INVALID_THREAD = 10, + JVMTI_ERROR_INVALID_THREAD_GROUP = 11, + JVMTI_ERROR_INVALID_PRIORITY = 12, + JVMTI_ERROR_THREAD_NOT_SUSPENDED = 13, + JVMTI_ERROR_THREAD_SUSPENDED = 14, + JVMTI_ERROR_THREAD_NOT_ALIVE = 15, + JVMTI_ERROR_INVALID_OBJECT = 20, + JVMTI_ERROR_INVALID_CLASS = 21, + JVMTI_ERROR_CLASS_NOT_PREPARED = 22, + JVMTI_ERROR_INVALID_METHODID = 23, + JVMTI_ERROR_INVALID_LOCATION = 24, + JVMTI_ERROR_INVALID_FIELDID = 25, + JVMTI_ERROR_NO_MORE_FRAMES = 31, + JVMTI_ERROR_OPAQUE_FRAME = 32, + JVMTI_ERROR_TYPE_MISMATCH = 34, + JVMTI_ERROR_INVALID_SLOT = 35, + JVMTI_ERROR_DUPLICATE = 40, + JVMTI_ERROR_NOT_FOUND = 41, + JVMTI_ERROR_INVALID_MONITOR = 50, + JVMTI_ERROR_NOT_MONITOR_OWNER = 51, + JVMTI_ERROR_INTERRUPT = 52, + JVMTI_ERROR_INVALID_CLASS_FORMAT = 60, + JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION = 61, + JVMTI_ERROR_FAILS_VERIFICATION = 62, + JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED = 63, + JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED = 64, + JVMTI_ERROR_INVALID_TYPESTATE = 65, + JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED = 66, + JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED = 67, + JVMTI_ERROR_UNSUPPORTED_VERSION = 68, + JVMTI_ERROR_NAMES_DONT_MATCH = 69, + JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED = 70, + JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED = 71, + JVMTI_ERROR_UNMODIFIABLE_CLASS = 79, + JVMTI_ERROR_NOT_AVAILABLE = 98, + JVMTI_ERROR_MUST_POSSESS_CAPABILITY = 99, + JVMTI_ERROR_NULL_POINTER = 100, + JVMTI_ERROR_ABSENT_INFORMATION = 101, + JVMTI_ERROR_INVALID_EVENT_TYPE = 102, + JVMTI_ERROR_ILLEGAL_ARGUMENT = 103, + JVMTI_ERROR_NATIVE_METHOD = 104, + JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED = 106, + JVMTI_ERROR_OUT_OF_MEMORY = 110, + JVMTI_ERROR_ACCESS_DENIED = 111, + JVMTI_ERROR_WRONG_PHASE = 112, + JVMTI_ERROR_INTERNAL = 113, + JVMTI_ERROR_UNATTACHED_THREAD = 115, + JVMTI_ERROR_INVALID_ENVIRONMENT = 116, + JVMTI_ERROR_MAX = 116 +} jvmtiError; + + /* Event IDs */ + +typedef enum { + JVMTI_MIN_EVENT_TYPE_VAL = 50, + JVMTI_EVENT_VM_INIT = 50, + JVMTI_EVENT_VM_DEATH = 51, + JVMTI_EVENT_THREAD_START = 52, + JVMTI_EVENT_THREAD_END = 53, + JVMTI_EVENT_CLASS_FILE_LOAD_HOOK = 54, + JVMTI_EVENT_CLASS_LOAD = 55, + JVMTI_EVENT_CLASS_PREPARE = 56, + JVMTI_EVENT_VM_START = 57, + JVMTI_EVENT_EXCEPTION = 58, + JVMTI_EVENT_EXCEPTION_CATCH = 59, + JVMTI_EVENT_SINGLE_STEP = 60, + JVMTI_EVENT_FRAME_POP = 61, + JVMTI_EVENT_BREAKPOINT = 62, + JVMTI_EVENT_FIELD_ACCESS = 63, + JVMTI_EVENT_FIELD_MODIFICATION = 64, + JVMTI_EVENT_METHOD_ENTRY = 65, + JVMTI_EVENT_METHOD_EXIT = 66, + JVMTI_EVENT_NATIVE_METHOD_BIND = 67, + JVMTI_EVENT_COMPILED_METHOD_LOAD = 68, + JVMTI_EVENT_COMPILED_METHOD_UNLOAD = 69, + JVMTI_EVENT_DYNAMIC_CODE_GENERATED = 70, + JVMTI_EVENT_DATA_DUMP_REQUEST = 71, + JVMTI_EVENT_MONITOR_WAIT = 73, + JVMTI_EVENT_MONITOR_WAITED = 74, + JVMTI_EVENT_MONITOR_CONTENDED_ENTER = 75, + JVMTI_EVENT_MONITOR_CONTENDED_ENTERED = 76, + JVMTI_EVENT_RESOURCE_EXHAUSTED = 80, + JVMTI_EVENT_GARBAGE_COLLECTION_START = 81, + JVMTI_EVENT_GARBAGE_COLLECTION_FINISH = 82, + JVMTI_EVENT_OBJECT_FREE = 83, + JVMTI_EVENT_VM_OBJECT_ALLOC = 84, + JVMTI_MAX_EVENT_TYPE_VAL = 84 +} jvmtiEvent; + + + /* Pre-Declarations */ +struct _jvmtiThreadInfo; +typedef struct _jvmtiThreadInfo jvmtiThreadInfo; +struct _jvmtiMonitorStackDepthInfo; +typedef struct _jvmtiMonitorStackDepthInfo jvmtiMonitorStackDepthInfo; +struct _jvmtiThreadGroupInfo; +typedef struct _jvmtiThreadGroupInfo jvmtiThreadGroupInfo; +struct _jvmtiFrameInfo; +typedef struct _jvmtiFrameInfo jvmtiFrameInfo; +struct _jvmtiStackInfo; +typedef struct _jvmtiStackInfo jvmtiStackInfo; +struct _jvmtiHeapReferenceInfoField; +typedef struct _jvmtiHeapReferenceInfoField jvmtiHeapReferenceInfoField; +struct _jvmtiHeapReferenceInfoArray; +typedef struct _jvmtiHeapReferenceInfoArray jvmtiHeapReferenceInfoArray; +struct _jvmtiHeapReferenceInfoConstantPool; +typedef struct _jvmtiHeapReferenceInfoConstantPool jvmtiHeapReferenceInfoConstantPool; +struct _jvmtiHeapReferenceInfoStackLocal; +typedef struct _jvmtiHeapReferenceInfoStackLocal jvmtiHeapReferenceInfoStackLocal; +struct _jvmtiHeapReferenceInfoJniLocal; +typedef struct _jvmtiHeapReferenceInfoJniLocal jvmtiHeapReferenceInfoJniLocal; +struct _jvmtiHeapReferenceInfoReserved; +typedef struct _jvmtiHeapReferenceInfoReserved jvmtiHeapReferenceInfoReserved; +union _jvmtiHeapReferenceInfo; +typedef union _jvmtiHeapReferenceInfo jvmtiHeapReferenceInfo; +struct _jvmtiHeapCallbacks; +typedef struct _jvmtiHeapCallbacks jvmtiHeapCallbacks; +struct _jvmtiClassDefinition; +typedef struct _jvmtiClassDefinition jvmtiClassDefinition; +struct _jvmtiMonitorUsage; +typedef struct _jvmtiMonitorUsage jvmtiMonitorUsage; +struct _jvmtiLineNumberEntry; +typedef struct _jvmtiLineNumberEntry jvmtiLineNumberEntry; +struct _jvmtiLocalVariableEntry; +typedef struct _jvmtiLocalVariableEntry jvmtiLocalVariableEntry; +struct _jvmtiParamInfo; +typedef struct _jvmtiParamInfo jvmtiParamInfo; +struct _jvmtiExtensionFunctionInfo; +typedef struct _jvmtiExtensionFunctionInfo jvmtiExtensionFunctionInfo; +struct _jvmtiExtensionEventInfo; +typedef struct _jvmtiExtensionEventInfo jvmtiExtensionEventInfo; +struct _jvmtiTimerInfo; +typedef struct _jvmtiTimerInfo jvmtiTimerInfo; +struct _jvmtiAddrLocationMap; +typedef struct _jvmtiAddrLocationMap jvmtiAddrLocationMap; + + /* Function Types */ + +typedef void (JNICALL *jvmtiStartFunction) + (jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg); + +typedef jint (JNICALL *jvmtiHeapIterationCallback) + (jlong class_tag, jlong size, jlong* tag_ptr, jint length, void* user_data); + +typedef jint (JNICALL *jvmtiHeapReferenceCallback) + (jvmtiHeapReferenceKind reference_kind, const jvmtiHeapReferenceInfo* reference_info, jlong class_tag, jlong referrer_class_tag, jlong size, jlong* tag_ptr, jlong* referrer_tag_ptr, jint length, void* user_data); + +typedef jint (JNICALL *jvmtiPrimitiveFieldCallback) + (jvmtiHeapReferenceKind kind, const jvmtiHeapReferenceInfo* info, jlong object_class_tag, jlong* object_tag_ptr, jvalue value, jvmtiPrimitiveType value_type, void* user_data); + +typedef jint (JNICALL *jvmtiArrayPrimitiveValueCallback) + (jlong class_tag, jlong size, jlong* tag_ptr, jint element_count, jvmtiPrimitiveType element_type, const void* elements, void* user_data); + +typedef jint (JNICALL *jvmtiStringPrimitiveValueCallback) + (jlong class_tag, jlong size, jlong* tag_ptr, const jchar* value, jint value_length, void* user_data); + +typedef jint (JNICALL *jvmtiReservedCallback) + (); + +typedef jvmtiIterationControl (JNICALL *jvmtiHeapObjectCallback) + (jlong class_tag, jlong size, jlong* tag_ptr, void* user_data); + +typedef jvmtiIterationControl (JNICALL *jvmtiHeapRootCallback) + (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, jlong* tag_ptr, void* user_data); + +typedef jvmtiIterationControl (JNICALL *jvmtiStackReferenceCallback) + (jvmtiHeapRootKind root_kind, jlong class_tag, jlong size, jlong* tag_ptr, jlong thread_tag, jint depth, jmethodID method, jint slot, void* user_data); + +typedef jvmtiIterationControl (JNICALL *jvmtiObjectReferenceCallback) + (jvmtiObjectReferenceKind reference_kind, jlong class_tag, jlong size, jlong* tag_ptr, jlong referrer_tag, jint referrer_index, void* user_data); + +typedef jvmtiError (JNICALL *jvmtiExtensionFunction) + (jvmtiEnv* jvmti_env, ...); + +typedef void (JNICALL *jvmtiExtensionEvent) + (jvmtiEnv* jvmti_env, ...); + + + /* Structure Types */ +struct _jvmtiThreadInfo { + char* name; + jint priority; + jboolean is_daemon; + jthreadGroup thread_group; + jobject context_class_loader; +}; +struct _jvmtiMonitorStackDepthInfo { + jobject monitor; + jint stack_depth; +}; +struct _jvmtiThreadGroupInfo { + jthreadGroup parent; + char* name; + jint max_priority; + jboolean is_daemon; +}; +struct _jvmtiFrameInfo { + jmethodID method; + jlocation location; +}; +struct _jvmtiStackInfo { + jthread thread; + jint state; + jvmtiFrameInfo* frame_buffer; + jint frame_count; +}; +struct _jvmtiHeapReferenceInfoField { + jint index; +}; +struct _jvmtiHeapReferenceInfoArray { + jint index; +}; +struct _jvmtiHeapReferenceInfoConstantPool { + jint index; +}; +struct _jvmtiHeapReferenceInfoStackLocal { + jlong thread_tag; + jlong thread_id; + jint depth; + jmethodID method; + jlocation location; + jint slot; +}; +struct _jvmtiHeapReferenceInfoJniLocal { + jlong thread_tag; + jlong thread_id; + jint depth; + jmethodID method; +}; +struct _jvmtiHeapReferenceInfoReserved { + jlong reserved1; + jlong reserved2; + jlong reserved3; + jlong reserved4; + jlong reserved5; + jlong reserved6; + jlong reserved7; + jlong reserved8; +}; +union _jvmtiHeapReferenceInfo { + jvmtiHeapReferenceInfoField field; + jvmtiHeapReferenceInfoArray array; + jvmtiHeapReferenceInfoConstantPool constant_pool; + jvmtiHeapReferenceInfoStackLocal stack_local; + jvmtiHeapReferenceInfoJniLocal jni_local; + jvmtiHeapReferenceInfoReserved other; +}; +struct _jvmtiHeapCallbacks { + jvmtiHeapIterationCallback heap_iteration_callback; + jvmtiHeapReferenceCallback heap_reference_callback; + jvmtiPrimitiveFieldCallback primitive_field_callback; + jvmtiArrayPrimitiveValueCallback array_primitive_value_callback; + jvmtiStringPrimitiveValueCallback string_primitive_value_callback; + jvmtiReservedCallback reserved5; + jvmtiReservedCallback reserved6; + jvmtiReservedCallback reserved7; + jvmtiReservedCallback reserved8; + jvmtiReservedCallback reserved9; + jvmtiReservedCallback reserved10; + jvmtiReservedCallback reserved11; + jvmtiReservedCallback reserved12; + jvmtiReservedCallback reserved13; + jvmtiReservedCallback reserved14; + jvmtiReservedCallback reserved15; +}; +struct _jvmtiClassDefinition { + jclass klass; + jint class_byte_count; + const unsigned char* class_bytes; +}; +struct _jvmtiMonitorUsage { + jthread owner; + jint entry_count; + jint waiter_count; + jthread* waiters; + jint notify_waiter_count; + jthread* notify_waiters; +}; +struct _jvmtiLineNumberEntry { + jlocation start_location; + jint line_number; +}; +struct _jvmtiLocalVariableEntry { + jlocation start_location; + jint length; + char* name; + char* signature; + char* generic_signature; + jint slot; +}; +struct _jvmtiParamInfo { + char* name; + jvmtiParamKind kind; + jvmtiParamTypes base_type; + jboolean null_ok; +}; +struct _jvmtiExtensionFunctionInfo { + jvmtiExtensionFunction func; + char* id; + char* short_description; + jint param_count; + jvmtiParamInfo* params; + jint error_count; + jvmtiError* errors; +}; +struct _jvmtiExtensionEventInfo { + jint extension_event_index; + char* id; + char* short_description; + jint param_count; + jvmtiParamInfo* params; +}; +struct _jvmtiTimerInfo { + jlong max_value; + jboolean may_skip_forward; + jboolean may_skip_backward; + jvmtiTimerKind kind; + jlong reserved1; + jlong reserved2; +}; +struct _jvmtiAddrLocationMap { + const void* start_address; + jlocation location; +}; + +typedef struct { + unsigned int can_tag_objects : 1; + unsigned int can_generate_field_modification_events : 1; + unsigned int can_generate_field_access_events : 1; + unsigned int can_get_bytecodes : 1; + unsigned int can_get_synthetic_attribute : 1; + unsigned int can_get_owned_monitor_info : 1; + unsigned int can_get_current_contended_monitor : 1; + unsigned int can_get_monitor_info : 1; + unsigned int can_pop_frame : 1; + unsigned int can_redefine_classes : 1; + unsigned int can_signal_thread : 1; + unsigned int can_get_source_file_name : 1; + unsigned int can_get_line_numbers : 1; + unsigned int can_get_source_debug_extension : 1; + unsigned int can_access_local_variables : 1; + unsigned int can_maintain_original_method_order : 1; + unsigned int can_generate_single_step_events : 1; + unsigned int can_generate_exception_events : 1; + unsigned int can_generate_frame_pop_events : 1; + unsigned int can_generate_breakpoint_events : 1; + unsigned int can_suspend : 1; + unsigned int can_redefine_any_class : 1; + unsigned int can_get_current_thread_cpu_time : 1; + unsigned int can_get_thread_cpu_time : 1; + unsigned int can_generate_method_entry_events : 1; + unsigned int can_generate_method_exit_events : 1; + unsigned int can_generate_all_class_hook_events : 1; + unsigned int can_generate_compiled_method_load_events : 1; + unsigned int can_generate_monitor_events : 1; + unsigned int can_generate_vm_object_alloc_events : 1; + unsigned int can_generate_native_method_bind_events : 1; + unsigned int can_generate_garbage_collection_events : 1; + unsigned int can_generate_object_free_events : 1; + unsigned int can_force_early_return : 1; + unsigned int can_get_owned_monitor_stack_depth_info : 1; + unsigned int can_get_constant_pool : 1; + unsigned int can_set_native_method_prefix : 1; + unsigned int can_retransform_classes : 1; + unsigned int can_retransform_any_class : 1; + unsigned int can_generate_resource_exhaustion_heap_events : 1; + unsigned int can_generate_resource_exhaustion_threads_events : 1; + unsigned int : 7; + unsigned int : 16; + unsigned int : 16; + unsigned int : 16; + unsigned int : 16; + unsigned int : 16; +} jvmtiCapabilities; + + + /* Event Definitions */ + +typedef void (JNICALL *jvmtiEventReserved)(void); + + +typedef void (JNICALL *jvmtiEventBreakpoint) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location); + +typedef void (JNICALL *jvmtiEventClassFileLoadHook) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jclass class_being_redefined, + jobject loader, + const char* name, + jobject protection_domain, + jint class_data_len, + const unsigned char* class_data, + jint* new_class_data_len, + unsigned char** new_class_data); + +typedef void (JNICALL *jvmtiEventClassLoad) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass); + +typedef void (JNICALL *jvmtiEventClassPrepare) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jclass klass); + +typedef void (JNICALL *jvmtiEventCompiledMethodLoad) + (jvmtiEnv *jvmti_env, + jmethodID method, + jint code_size, + const void* code_addr, + jint map_length, + const jvmtiAddrLocationMap* map, + const void* compile_info); + +typedef void (JNICALL *jvmtiEventCompiledMethodUnload) + (jvmtiEnv *jvmti_env, + jmethodID method, + const void* code_addr); + +typedef void (JNICALL *jvmtiEventDataDumpRequest) + (jvmtiEnv *jvmti_env); + +typedef void (JNICALL *jvmtiEventDynamicCodeGenerated) + (jvmtiEnv *jvmti_env, + const char* name, + const void* address, + jint length); + +typedef void (JNICALL *jvmtiEventException) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location, + jobject exception, + jmethodID catch_method, + jlocation catch_location); + +typedef void (JNICALL *jvmtiEventExceptionCatch) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location, + jobject exception); + +typedef void (JNICALL *jvmtiEventFieldAccess) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location, + jclass field_klass, + jobject object, + jfieldID field); + +typedef void (JNICALL *jvmtiEventFieldModification) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location, + jclass field_klass, + jobject object, + jfieldID field, + char signature_type, + jvalue new_value); + +typedef void (JNICALL *jvmtiEventFramePop) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jboolean was_popped_by_exception); + +typedef void (JNICALL *jvmtiEventGarbageCollectionFinish) + (jvmtiEnv *jvmti_env); + +typedef void (JNICALL *jvmtiEventGarbageCollectionStart) + (jvmtiEnv *jvmti_env); + +typedef void (JNICALL *jvmtiEventMethodEntry) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method); + +typedef void (JNICALL *jvmtiEventMethodExit) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jboolean was_popped_by_exception, + jvalue return_value); + +typedef void (JNICALL *jvmtiEventMonitorContendedEnter) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jobject object); + +typedef void (JNICALL *jvmtiEventMonitorContendedEntered) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jobject object); + +typedef void (JNICALL *jvmtiEventMonitorWait) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jobject object, + jlong timeout); + +typedef void (JNICALL *jvmtiEventMonitorWaited) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jobject object, + jboolean timed_out); + +typedef void (JNICALL *jvmtiEventNativeMethodBind) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + void* address, + void** new_address_ptr); + +typedef void (JNICALL *jvmtiEventObjectFree) + (jvmtiEnv *jvmti_env, + jlong tag); + +typedef void (JNICALL *jvmtiEventResourceExhausted) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jint flags, + const void* reserved, + const char* description); + +typedef void (JNICALL *jvmtiEventSingleStep) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jlocation location); + +typedef void (JNICALL *jvmtiEventThreadEnd) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread); + +typedef void (JNICALL *jvmtiEventThreadStart) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread); + +typedef void (JNICALL *jvmtiEventVMDeath) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env); + +typedef void (JNICALL *jvmtiEventVMInit) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread); + +typedef void (JNICALL *jvmtiEventVMObjectAlloc) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jobject object, + jclass object_klass, + jlong size); + +typedef void (JNICALL *jvmtiEventVMStart) + (jvmtiEnv *jvmti_env, + JNIEnv* jni_env); + + /* Event Callback Structure */ + +typedef struct { + /* 50 : VM Initialization Event */ + jvmtiEventVMInit VMInit; + /* 51 : VM Death Event */ + jvmtiEventVMDeath VMDeath; + /* 52 : Thread Start */ + jvmtiEventThreadStart ThreadStart; + /* 53 : Thread End */ + jvmtiEventThreadEnd ThreadEnd; + /* 54 : Class File Load Hook */ + jvmtiEventClassFileLoadHook ClassFileLoadHook; + /* 55 : Class Load */ + jvmtiEventClassLoad ClassLoad; + /* 56 : Class Prepare */ + jvmtiEventClassPrepare ClassPrepare; + /* 57 : VM Start Event */ + jvmtiEventVMStart VMStart; + /* 58 : Exception */ + jvmtiEventException Exception; + /* 59 : Exception Catch */ + jvmtiEventExceptionCatch ExceptionCatch; + /* 60 : Single Step */ + jvmtiEventSingleStep SingleStep; + /* 61 : Frame Pop */ + jvmtiEventFramePop FramePop; + /* 62 : Breakpoint */ + jvmtiEventBreakpoint Breakpoint; + /* 63 : Field Access */ + jvmtiEventFieldAccess FieldAccess; + /* 64 : Field Modification */ + jvmtiEventFieldModification FieldModification; + /* 65 : Method Entry */ + jvmtiEventMethodEntry MethodEntry; + /* 66 : Method Exit */ + jvmtiEventMethodExit MethodExit; + /* 67 : Native Method Bind */ + jvmtiEventNativeMethodBind NativeMethodBind; + /* 68 : Compiled Method Load */ + jvmtiEventCompiledMethodLoad CompiledMethodLoad; + /* 69 : Compiled Method Unload */ + jvmtiEventCompiledMethodUnload CompiledMethodUnload; + /* 70 : Dynamic Code Generated */ + jvmtiEventDynamicCodeGenerated DynamicCodeGenerated; + /* 71 : Data Dump Request */ + jvmtiEventDataDumpRequest DataDumpRequest; + /* 72 */ + jvmtiEventReserved reserved72; + /* 73 : Monitor Wait */ + jvmtiEventMonitorWait MonitorWait; + /* 74 : Monitor Waited */ + jvmtiEventMonitorWaited MonitorWaited; + /* 75 : Monitor Contended Enter */ + jvmtiEventMonitorContendedEnter MonitorContendedEnter; + /* 76 : Monitor Contended Entered */ + jvmtiEventMonitorContendedEntered MonitorContendedEntered; + /* 77 */ + jvmtiEventReserved reserved77; + /* 78 */ + jvmtiEventReserved reserved78; + /* 79 */ + jvmtiEventReserved reserved79; + /* 80 : Resource Exhausted */ + jvmtiEventResourceExhausted ResourceExhausted; + /* 81 : Garbage Collection Start */ + jvmtiEventGarbageCollectionStart GarbageCollectionStart; + /* 82 : Garbage Collection Finish */ + jvmtiEventGarbageCollectionFinish GarbageCollectionFinish; + /* 83 : Object Free */ + jvmtiEventObjectFree ObjectFree; + /* 84 : VM Object Allocation */ + jvmtiEventVMObjectAlloc VMObjectAlloc; +} jvmtiEventCallbacks; + + + /* Function Interface */ + +typedef struct jvmtiInterface_1_ { + + /* 1 : RESERVED */ + void *reserved1; + + /* 2 : Set Event Notification Mode */ + jvmtiError (JNICALL *SetEventNotificationMode) (jvmtiEnv* env, + jvmtiEventMode mode, + jvmtiEvent event_type, + jthread event_thread, + ...); + + /* 3 : RESERVED */ + void *reserved3; + + /* 4 : Get All Threads */ + jvmtiError (JNICALL *GetAllThreads) (jvmtiEnv* env, + jint* threads_count_ptr, + jthread** threads_ptr); + + /* 5 : Suspend Thread */ + jvmtiError (JNICALL *SuspendThread) (jvmtiEnv* env, + jthread thread); + + /* 6 : Resume Thread */ + jvmtiError (JNICALL *ResumeThread) (jvmtiEnv* env, + jthread thread); + + /* 7 : Stop Thread */ + jvmtiError (JNICALL *StopThread) (jvmtiEnv* env, + jthread thread, + jobject exception); + + /* 8 : Interrupt Thread */ + jvmtiError (JNICALL *InterruptThread) (jvmtiEnv* env, + jthread thread); + + /* 9 : Get Thread Info */ + jvmtiError (JNICALL *GetThreadInfo) (jvmtiEnv* env, + jthread thread, + jvmtiThreadInfo* info_ptr); + + /* 10 : Get Owned Monitor Info */ + jvmtiError (JNICALL *GetOwnedMonitorInfo) (jvmtiEnv* env, + jthread thread, + jint* owned_monitor_count_ptr, + jobject** owned_monitors_ptr); + + /* 11 : Get Current Contended Monitor */ + jvmtiError (JNICALL *GetCurrentContendedMonitor) (jvmtiEnv* env, + jthread thread, + jobject* monitor_ptr); + + /* 12 : Run Agent Thread */ + jvmtiError (JNICALL *RunAgentThread) (jvmtiEnv* env, + jthread thread, + jvmtiStartFunction proc, + const void* arg, + jint priority); + + /* 13 : Get Top Thread Groups */ + jvmtiError (JNICALL *GetTopThreadGroups) (jvmtiEnv* env, + jint* group_count_ptr, + jthreadGroup** groups_ptr); + + /* 14 : Get Thread Group Info */ + jvmtiError (JNICALL *GetThreadGroupInfo) (jvmtiEnv* env, + jthreadGroup group, + jvmtiThreadGroupInfo* info_ptr); + + /* 15 : Get Thread Group Children */ + jvmtiError (JNICALL *GetThreadGroupChildren) (jvmtiEnv* env, + jthreadGroup group, + jint* thread_count_ptr, + jthread** threads_ptr, + jint* group_count_ptr, + jthreadGroup** groups_ptr); + + /* 16 : Get Frame Count */ + jvmtiError (JNICALL *GetFrameCount) (jvmtiEnv* env, + jthread thread, + jint* count_ptr); + + /* 17 : Get Thread State */ + jvmtiError (JNICALL *GetThreadState) (jvmtiEnv* env, + jthread thread, + jint* thread_state_ptr); + + /* 18 : Get Current Thread */ + jvmtiError (JNICALL *GetCurrentThread) (jvmtiEnv* env, + jthread* thread_ptr); + + /* 19 : Get Frame Location */ + jvmtiError (JNICALL *GetFrameLocation) (jvmtiEnv* env, + jthread thread, + jint depth, + jmethodID* method_ptr, + jlocation* location_ptr); + + /* 20 : Notify Frame Pop */ + jvmtiError (JNICALL *NotifyFramePop) (jvmtiEnv* env, + jthread thread, + jint depth); + + /* 21 : Get Local Variable - Object */ + jvmtiError (JNICALL *GetLocalObject) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jobject* value_ptr); + + /* 22 : Get Local Variable - Int */ + jvmtiError (JNICALL *GetLocalInt) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jint* value_ptr); + + /* 23 : Get Local Variable - Long */ + jvmtiError (JNICALL *GetLocalLong) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jlong* value_ptr); + + /* 24 : Get Local Variable - Float */ + jvmtiError (JNICALL *GetLocalFloat) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jfloat* value_ptr); + + /* 25 : Get Local Variable - Double */ + jvmtiError (JNICALL *GetLocalDouble) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jdouble* value_ptr); + + /* 26 : Set Local Variable - Object */ + jvmtiError (JNICALL *SetLocalObject) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jobject value); + + /* 27 : Set Local Variable - Int */ + jvmtiError (JNICALL *SetLocalInt) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jint value); + + /* 28 : Set Local Variable - Long */ + jvmtiError (JNICALL *SetLocalLong) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jlong value); + + /* 29 : Set Local Variable - Float */ + jvmtiError (JNICALL *SetLocalFloat) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jfloat value); + + /* 30 : Set Local Variable - Double */ + jvmtiError (JNICALL *SetLocalDouble) (jvmtiEnv* env, + jthread thread, + jint depth, + jint slot, + jdouble value); + + /* 31 : Create Raw Monitor */ + jvmtiError (JNICALL *CreateRawMonitor) (jvmtiEnv* env, + const char* name, + jrawMonitorID* monitor_ptr); + + /* 32 : Destroy Raw Monitor */ + jvmtiError (JNICALL *DestroyRawMonitor) (jvmtiEnv* env, + jrawMonitorID monitor); + + /* 33 : Raw Monitor Enter */ + jvmtiError (JNICALL *RawMonitorEnter) (jvmtiEnv* env, + jrawMonitorID monitor); + + /* 34 : Raw Monitor Exit */ + jvmtiError (JNICALL *RawMonitorExit) (jvmtiEnv* env, + jrawMonitorID monitor); + + /* 35 : Raw Monitor Wait */ + jvmtiError (JNICALL *RawMonitorWait) (jvmtiEnv* env, + jrawMonitorID monitor, + jlong millis); + + /* 36 : Raw Monitor Notify */ + jvmtiError (JNICALL *RawMonitorNotify) (jvmtiEnv* env, + jrawMonitorID monitor); + + /* 37 : Raw Monitor Notify All */ + jvmtiError (JNICALL *RawMonitorNotifyAll) (jvmtiEnv* env, + jrawMonitorID monitor); + + /* 38 : Set Breakpoint */ + jvmtiError (JNICALL *SetBreakpoint) (jvmtiEnv* env, + jmethodID method, + jlocation location); + + /* 39 : Clear Breakpoint */ + jvmtiError (JNICALL *ClearBreakpoint) (jvmtiEnv* env, + jmethodID method, + jlocation location); + + /* 40 : RESERVED */ + void *reserved40; + + /* 41 : Set Field Access Watch */ + jvmtiError (JNICALL *SetFieldAccessWatch) (jvmtiEnv* env, + jclass klass, + jfieldID field); + + /* 42 : Clear Field Access Watch */ + jvmtiError (JNICALL *ClearFieldAccessWatch) (jvmtiEnv* env, + jclass klass, + jfieldID field); + + /* 43 : Set Field Modification Watch */ + jvmtiError (JNICALL *SetFieldModificationWatch) (jvmtiEnv* env, + jclass klass, + jfieldID field); + + /* 44 : Clear Field Modification Watch */ + jvmtiError (JNICALL *ClearFieldModificationWatch) (jvmtiEnv* env, + jclass klass, + jfieldID field); + + /* 45 : Is Modifiable Class */ + jvmtiError (JNICALL *IsModifiableClass) (jvmtiEnv* env, + jclass klass, + jboolean* is_modifiable_class_ptr); + + /* 46 : Allocate */ + jvmtiError (JNICALL *Allocate) (jvmtiEnv* env, + jlong size, + unsigned char** mem_ptr); + + /* 47 : Deallocate */ + jvmtiError (JNICALL *Deallocate) (jvmtiEnv* env, + unsigned char* mem); + + /* 48 : Get Class Signature */ + jvmtiError (JNICALL *GetClassSignature) (jvmtiEnv* env, + jclass klass, + char** signature_ptr, + char** generic_ptr); + + /* 49 : Get Class Status */ + jvmtiError (JNICALL *GetClassStatus) (jvmtiEnv* env, + jclass klass, + jint* status_ptr); + + /* 50 : Get Source File Name */ + jvmtiError (JNICALL *GetSourceFileName) (jvmtiEnv* env, + jclass klass, + char** source_name_ptr); + + /* 51 : Get Class Modifiers */ + jvmtiError (JNICALL *GetClassModifiers) (jvmtiEnv* env, + jclass klass, + jint* modifiers_ptr); + + /* 52 : Get Class Methods */ + jvmtiError (JNICALL *GetClassMethods) (jvmtiEnv* env, + jclass klass, + jint* method_count_ptr, + jmethodID** methods_ptr); + + /* 53 : Get Class Fields */ + jvmtiError (JNICALL *GetClassFields) (jvmtiEnv* env, + jclass klass, + jint* field_count_ptr, + jfieldID** fields_ptr); + + /* 54 : Get Implemented Interfaces */ + jvmtiError (JNICALL *GetImplementedInterfaces) (jvmtiEnv* env, + jclass klass, + jint* interface_count_ptr, + jclass** interfaces_ptr); + + /* 55 : Is Interface */ + jvmtiError (JNICALL *IsInterface) (jvmtiEnv* env, + jclass klass, + jboolean* is_interface_ptr); + + /* 56 : Is Array Class */ + jvmtiError (JNICALL *IsArrayClass) (jvmtiEnv* env, + jclass klass, + jboolean* is_array_class_ptr); + + /* 57 : Get Class Loader */ + jvmtiError (JNICALL *GetClassLoader) (jvmtiEnv* env, + jclass klass, + jobject* classloader_ptr); + + /* 58 : Get Object Hash Code */ + jvmtiError (JNICALL *GetObjectHashCode) (jvmtiEnv* env, + jobject object, + jint* hash_code_ptr); + + /* 59 : Get Object Monitor Usage */ + jvmtiError (JNICALL *GetObjectMonitorUsage) (jvmtiEnv* env, + jobject object, + jvmtiMonitorUsage* info_ptr); + + /* 60 : Get Field Name (and Signature) */ + jvmtiError (JNICALL *GetFieldName) (jvmtiEnv* env, + jclass klass, + jfieldID field, + char** name_ptr, + char** signature_ptr, + char** generic_ptr); + + /* 61 : Get Field Declaring Class */ + jvmtiError (JNICALL *GetFieldDeclaringClass) (jvmtiEnv* env, + jclass klass, + jfieldID field, + jclass* declaring_class_ptr); + + /* 62 : Get Field Modifiers */ + jvmtiError (JNICALL *GetFieldModifiers) (jvmtiEnv* env, + jclass klass, + jfieldID field, + jint* modifiers_ptr); + + /* 63 : Is Field Synthetic */ + jvmtiError (JNICALL *IsFieldSynthetic) (jvmtiEnv* env, + jclass klass, + jfieldID field, + jboolean* is_synthetic_ptr); + + /* 64 : Get Method Name (and Signature) */ + jvmtiError (JNICALL *GetMethodName) (jvmtiEnv* env, + jmethodID method, + char** name_ptr, + char** signature_ptr, + char** generic_ptr); + + /* 65 : Get Method Declaring Class */ + jvmtiError (JNICALL *GetMethodDeclaringClass) (jvmtiEnv* env, + jmethodID method, + jclass* declaring_class_ptr); + + /* 66 : Get Method Modifiers */ + jvmtiError (JNICALL *GetMethodModifiers) (jvmtiEnv* env, + jmethodID method, + jint* modifiers_ptr); + + /* 67 : RESERVED */ + void *reserved67; + + /* 68 : Get Max Locals */ + jvmtiError (JNICALL *GetMaxLocals) (jvmtiEnv* env, + jmethodID method, + jint* max_ptr); + + /* 69 : Get Arguments Size */ + jvmtiError (JNICALL *GetArgumentsSize) (jvmtiEnv* env, + jmethodID method, + jint* size_ptr); + + /* 70 : Get Line Number Table */ + jvmtiError (JNICALL *GetLineNumberTable) (jvmtiEnv* env, + jmethodID method, + jint* entry_count_ptr, + jvmtiLineNumberEntry** table_ptr); + + /* 71 : Get Method Location */ + jvmtiError (JNICALL *GetMethodLocation) (jvmtiEnv* env, + jmethodID method, + jlocation* start_location_ptr, + jlocation* end_location_ptr); + + /* 72 : Get Local Variable Table */ + jvmtiError (JNICALL *GetLocalVariableTable) (jvmtiEnv* env, + jmethodID method, + jint* entry_count_ptr, + jvmtiLocalVariableEntry** table_ptr); + + /* 73 : Set Native Method Prefix */ + jvmtiError (JNICALL *SetNativeMethodPrefix) (jvmtiEnv* env, + const char* prefix); + + /* 74 : Set Native Method Prefixes */ + jvmtiError (JNICALL *SetNativeMethodPrefixes) (jvmtiEnv* env, + jint prefix_count, + char** prefixes); + + /* 75 : Get Bytecodes */ + jvmtiError (JNICALL *GetBytecodes) (jvmtiEnv* env, + jmethodID method, + jint* bytecode_count_ptr, + unsigned char** bytecodes_ptr); + + /* 76 : Is Method Native */ + jvmtiError (JNICALL *IsMethodNative) (jvmtiEnv* env, + jmethodID method, + jboolean* is_native_ptr); + + /* 77 : Is Method Synthetic */ + jvmtiError (JNICALL *IsMethodSynthetic) (jvmtiEnv* env, + jmethodID method, + jboolean* is_synthetic_ptr); + + /* 78 : Get Loaded Classes */ + jvmtiError (JNICALL *GetLoadedClasses) (jvmtiEnv* env, + jint* class_count_ptr, + jclass** classes_ptr); + + /* 79 : Get Classloader Classes */ + jvmtiError (JNICALL *GetClassLoaderClasses) (jvmtiEnv* env, + jobject initiating_loader, + jint* class_count_ptr, + jclass** classes_ptr); + + /* 80 : Pop Frame */ + jvmtiError (JNICALL *PopFrame) (jvmtiEnv* env, + jthread thread); + + /* 81 : Force Early Return - Object */ + jvmtiError (JNICALL *ForceEarlyReturnObject) (jvmtiEnv* env, + jthread thread, + jobject value); + + /* 82 : Force Early Return - Int */ + jvmtiError (JNICALL *ForceEarlyReturnInt) (jvmtiEnv* env, + jthread thread, + jint value); + + /* 83 : Force Early Return - Long */ + jvmtiError (JNICALL *ForceEarlyReturnLong) (jvmtiEnv* env, + jthread thread, + jlong value); + + /* 84 : Force Early Return - Float */ + jvmtiError (JNICALL *ForceEarlyReturnFloat) (jvmtiEnv* env, + jthread thread, + jfloat value); + + /* 85 : Force Early Return - Double */ + jvmtiError (JNICALL *ForceEarlyReturnDouble) (jvmtiEnv* env, + jthread thread, + jdouble value); + + /* 86 : Force Early Return - Void */ + jvmtiError (JNICALL *ForceEarlyReturnVoid) (jvmtiEnv* env, + jthread thread); + + /* 87 : Redefine Classes */ + jvmtiError (JNICALL *RedefineClasses) (jvmtiEnv* env, + jint class_count, + const jvmtiClassDefinition* class_definitions); + + /* 88 : Get Version Number */ + jvmtiError (JNICALL *GetVersionNumber) (jvmtiEnv* env, + jint* version_ptr); + + /* 89 : Get Capabilities */ + jvmtiError (JNICALL *GetCapabilities) (jvmtiEnv* env, + jvmtiCapabilities* capabilities_ptr); + + /* 90 : Get Source Debug Extension */ + jvmtiError (JNICALL *GetSourceDebugExtension) (jvmtiEnv* env, + jclass klass, + char** source_debug_extension_ptr); + + /* 91 : Is Method Obsolete */ + jvmtiError (JNICALL *IsMethodObsolete) (jvmtiEnv* env, + jmethodID method, + jboolean* is_obsolete_ptr); + + /* 92 : Suspend Thread List */ + jvmtiError (JNICALL *SuspendThreadList) (jvmtiEnv* env, + jint request_count, + const jthread* request_list, + jvmtiError* results); + + /* 93 : Resume Thread List */ + jvmtiError (JNICALL *ResumeThreadList) (jvmtiEnv* env, + jint request_count, + const jthread* request_list, + jvmtiError* results); + + /* 94 : RESERVED */ + void *reserved94; + + /* 95 : RESERVED */ + void *reserved95; + + /* 96 : RESERVED */ + void *reserved96; + + /* 97 : RESERVED */ + void *reserved97; + + /* 98 : RESERVED */ + void *reserved98; + + /* 99 : RESERVED */ + void *reserved99; + + /* 100 : Get All Stack Traces */ + jvmtiError (JNICALL *GetAllStackTraces) (jvmtiEnv* env, + jint max_frame_count, + jvmtiStackInfo** stack_info_ptr, + jint* thread_count_ptr); + + /* 101 : Get Thread List Stack Traces */ + jvmtiError (JNICALL *GetThreadListStackTraces) (jvmtiEnv* env, + jint thread_count, + const jthread* thread_list, + jint max_frame_count, + jvmtiStackInfo** stack_info_ptr); + + /* 102 : Get Thread Local Storage */ + jvmtiError (JNICALL *GetThreadLocalStorage) (jvmtiEnv* env, + jthread thread, + void** data_ptr); + + /* 103 : Set Thread Local Storage */ + jvmtiError (JNICALL *SetThreadLocalStorage) (jvmtiEnv* env, + jthread thread, + const void* data); + + /* 104 : Get Stack Trace */ + jvmtiError (JNICALL *GetStackTrace) (jvmtiEnv* env, + jthread thread, + jint start_depth, + jint max_frame_count, + jvmtiFrameInfo* frame_buffer, + jint* count_ptr); + + /* 105 : RESERVED */ + void *reserved105; + + /* 106 : Get Tag */ + jvmtiError (JNICALL *GetTag) (jvmtiEnv* env, + jobject object, + jlong* tag_ptr); + + /* 107 : Set Tag */ + jvmtiError (JNICALL *SetTag) (jvmtiEnv* env, + jobject object, + jlong tag); + + /* 108 : Force Garbage Collection */ + jvmtiError (JNICALL *ForceGarbageCollection) (jvmtiEnv* env); + + /* 109 : Iterate Over Objects Reachable From Object */ + jvmtiError (JNICALL *IterateOverObjectsReachableFromObject) (jvmtiEnv* env, + jobject object, + jvmtiObjectReferenceCallback object_reference_callback, + const void* user_data); + + /* 110 : Iterate Over Reachable Objects */ + jvmtiError (JNICALL *IterateOverReachableObjects) (jvmtiEnv* env, + jvmtiHeapRootCallback heap_root_callback, + jvmtiStackReferenceCallback stack_ref_callback, + jvmtiObjectReferenceCallback object_ref_callback, + const void* user_data); + + /* 111 : Iterate Over Heap */ + jvmtiError (JNICALL *IterateOverHeap) (jvmtiEnv* env, + jvmtiHeapObjectFilter object_filter, + jvmtiHeapObjectCallback heap_object_callback, + const void* user_data); + + /* 112 : Iterate Over Instances Of Class */ + jvmtiError (JNICALL *IterateOverInstancesOfClass) (jvmtiEnv* env, + jclass klass, + jvmtiHeapObjectFilter object_filter, + jvmtiHeapObjectCallback heap_object_callback, + const void* user_data); + + /* 113 : RESERVED */ + void *reserved113; + + /* 114 : Get Objects With Tags */ + jvmtiError (JNICALL *GetObjectsWithTags) (jvmtiEnv* env, + jint tag_count, + const jlong* tags, + jint* count_ptr, + jobject** object_result_ptr, + jlong** tag_result_ptr); + + /* 115 : Follow References */ + jvmtiError (JNICALL *FollowReferences) (jvmtiEnv* env, + jint heap_filter, + jclass klass, + jobject initial_object, + const jvmtiHeapCallbacks* callbacks, + const void* user_data); + + /* 116 : Iterate Through Heap */ + jvmtiError (JNICALL *IterateThroughHeap) (jvmtiEnv* env, + jint heap_filter, + jclass klass, + const jvmtiHeapCallbacks* callbacks, + const void* user_data); + + /* 117 : RESERVED */ + void *reserved117; + + /* 118 : RESERVED */ + void *reserved118; + + /* 119 : RESERVED */ + void *reserved119; + + /* 120 : Set JNI Function Table */ + jvmtiError (JNICALL *SetJNIFunctionTable) (jvmtiEnv* env, + const jniNativeInterface* function_table); + + /* 121 : Get JNI Function Table */ + jvmtiError (JNICALL *GetJNIFunctionTable) (jvmtiEnv* env, + jniNativeInterface** function_table); + + /* 122 : Set Event Callbacks */ + jvmtiError (JNICALL *SetEventCallbacks) (jvmtiEnv* env, + const jvmtiEventCallbacks* callbacks, + jint size_of_callbacks); + + /* 123 : Generate Events */ + jvmtiError (JNICALL *GenerateEvents) (jvmtiEnv* env, + jvmtiEvent event_type); + + /* 124 : Get Extension Functions */ + jvmtiError (JNICALL *GetExtensionFunctions) (jvmtiEnv* env, + jint* extension_count_ptr, + jvmtiExtensionFunctionInfo** extensions); + + /* 125 : Get Extension Events */ + jvmtiError (JNICALL *GetExtensionEvents) (jvmtiEnv* env, + jint* extension_count_ptr, + jvmtiExtensionEventInfo** extensions); + + /* 126 : Set Extension Event Callback */ + jvmtiError (JNICALL *SetExtensionEventCallback) (jvmtiEnv* env, + jint extension_event_index, + jvmtiExtensionEvent callback); + + /* 127 : Dispose Environment */ + jvmtiError (JNICALL *DisposeEnvironment) (jvmtiEnv* env); + + /* 128 : Get Error Name */ + jvmtiError (JNICALL *GetErrorName) (jvmtiEnv* env, + jvmtiError error, + char** name_ptr); + + /* 129 : Get JLocation Format */ + jvmtiError (JNICALL *GetJLocationFormat) (jvmtiEnv* env, + jvmtiJlocationFormat* format_ptr); + + /* 130 : Get System Properties */ + jvmtiError (JNICALL *GetSystemProperties) (jvmtiEnv* env, + jint* count_ptr, + char*** property_ptr); + + /* 131 : Get System Property */ + jvmtiError (JNICALL *GetSystemProperty) (jvmtiEnv* env, + const char* property, + char** value_ptr); + + /* 132 : Set System Property */ + jvmtiError (JNICALL *SetSystemProperty) (jvmtiEnv* env, + const char* property, + const char* value); + + /* 133 : Get Phase */ + jvmtiError (JNICALL *GetPhase) (jvmtiEnv* env, + jvmtiPhase* phase_ptr); + + /* 134 : Get Current Thread CPU Timer Information */ + jvmtiError (JNICALL *GetCurrentThreadCpuTimerInfo) (jvmtiEnv* env, + jvmtiTimerInfo* info_ptr); + + /* 135 : Get Current Thread CPU Time */ + jvmtiError (JNICALL *GetCurrentThreadCpuTime) (jvmtiEnv* env, + jlong* nanos_ptr); + + /* 136 : Get Thread CPU Timer Information */ + jvmtiError (JNICALL *GetThreadCpuTimerInfo) (jvmtiEnv* env, + jvmtiTimerInfo* info_ptr); + + /* 137 : Get Thread CPU Time */ + jvmtiError (JNICALL *GetThreadCpuTime) (jvmtiEnv* env, + jthread thread, + jlong* nanos_ptr); + + /* 138 : Get Timer Information */ + jvmtiError (JNICALL *GetTimerInfo) (jvmtiEnv* env, + jvmtiTimerInfo* info_ptr); + + /* 139 : Get Time */ + jvmtiError (JNICALL *GetTime) (jvmtiEnv* env, + jlong* nanos_ptr); + + /* 140 : Get Potential Capabilities */ + jvmtiError (JNICALL *GetPotentialCapabilities) (jvmtiEnv* env, + jvmtiCapabilities* capabilities_ptr); + + /* 141 : RESERVED */ + void *reserved141; + + /* 142 : Add Capabilities */ + jvmtiError (JNICALL *AddCapabilities) (jvmtiEnv* env, + const jvmtiCapabilities* capabilities_ptr); + + /* 143 : Relinquish Capabilities */ + jvmtiError (JNICALL *RelinquishCapabilities) (jvmtiEnv* env, + const jvmtiCapabilities* capabilities_ptr); + + /* 144 : Get Available Processors */ + jvmtiError (JNICALL *GetAvailableProcessors) (jvmtiEnv* env, + jint* processor_count_ptr); + + /* 145 : Get Class Version Numbers */ + jvmtiError (JNICALL *GetClassVersionNumbers) (jvmtiEnv* env, + jclass klass, + jint* minor_version_ptr, + jint* major_version_ptr); + + /* 146 : Get Constant Pool */ + jvmtiError (JNICALL *GetConstantPool) (jvmtiEnv* env, + jclass klass, + jint* constant_pool_count_ptr, + jint* constant_pool_byte_count_ptr, + unsigned char** constant_pool_bytes_ptr); + + /* 147 : Get Environment Local Storage */ + jvmtiError (JNICALL *GetEnvironmentLocalStorage) (jvmtiEnv* env, + void** data_ptr); + + /* 148 : Set Environment Local Storage */ + jvmtiError (JNICALL *SetEnvironmentLocalStorage) (jvmtiEnv* env, + const void* data); + + /* 149 : Add To Bootstrap Class Loader Search */ + jvmtiError (JNICALL *AddToBootstrapClassLoaderSearch) (jvmtiEnv* env, + const char* segment); + + /* 150 : Set Verbose Flag */ + jvmtiError (JNICALL *SetVerboseFlag) (jvmtiEnv* env, + jvmtiVerboseFlag flag, + jboolean value); + + /* 151 : Add To System Class Loader Search */ + jvmtiError (JNICALL *AddToSystemClassLoaderSearch) (jvmtiEnv* env, + const char* segment); + + /* 152 : Retransform Classes */ + jvmtiError (JNICALL *RetransformClasses) (jvmtiEnv* env, + jint class_count, + const jclass* classes); + + /* 153 : Get Owned Monitor Stack Depth Info */ + jvmtiError (JNICALL *GetOwnedMonitorStackDepthInfo) (jvmtiEnv* env, + jthread thread, + jint* monitor_info_count_ptr, + jvmtiMonitorStackDepthInfo** monitor_info_ptr); + + /* 154 : Get Object Size */ + jvmtiError (JNICALL *GetObjectSize) (jvmtiEnv* env, + jobject object, + jlong* size_ptr); + + /* 155 : Get Local Instance */ + jvmtiError (JNICALL *GetLocalInstance) (jvmtiEnv* env, + jthread thread, + jint depth, + jobject* value_ptr); + +} jvmtiInterface_1; + +struct _jvmtiEnv { + const struct jvmtiInterface_1_ *functions; +#ifdef __cplusplus + + + jvmtiError Allocate(jlong size, + unsigned char** mem_ptr) { + return functions->Allocate(this, size, mem_ptr); + } + + jvmtiError Deallocate(unsigned char* mem) { + return functions->Deallocate(this, mem); + } + + jvmtiError GetThreadState(jthread thread, + jint* thread_state_ptr) { + return functions->GetThreadState(this, thread, thread_state_ptr); + } + + jvmtiError GetCurrentThread(jthread* thread_ptr) { + return functions->GetCurrentThread(this, thread_ptr); + } + + jvmtiError GetAllThreads(jint* threads_count_ptr, + jthread** threads_ptr) { + return functions->GetAllThreads(this, threads_count_ptr, threads_ptr); + } + + jvmtiError SuspendThread(jthread thread) { + return functions->SuspendThread(this, thread); + } + + jvmtiError SuspendThreadList(jint request_count, + const jthread* request_list, + jvmtiError* results) { + return functions->SuspendThreadList(this, request_count, request_list, results); + } + + jvmtiError ResumeThread(jthread thread) { + return functions->ResumeThread(this, thread); + } + + jvmtiError ResumeThreadList(jint request_count, + const jthread* request_list, + jvmtiError* results) { + return functions->ResumeThreadList(this, request_count, request_list, results); + } + + jvmtiError StopThread(jthread thread, + jobject exception) { + return functions->StopThread(this, thread, exception); + } + + jvmtiError InterruptThread(jthread thread) { + return functions->InterruptThread(this, thread); + } + + jvmtiError GetThreadInfo(jthread thread, + jvmtiThreadInfo* info_ptr) { + return functions->GetThreadInfo(this, thread, info_ptr); + } + + jvmtiError GetOwnedMonitorInfo(jthread thread, + jint* owned_monitor_count_ptr, + jobject** owned_monitors_ptr) { + return functions->GetOwnedMonitorInfo(this, thread, owned_monitor_count_ptr, owned_monitors_ptr); + } + + jvmtiError GetOwnedMonitorStackDepthInfo(jthread thread, + jint* monitor_info_count_ptr, + jvmtiMonitorStackDepthInfo** monitor_info_ptr) { + return functions->GetOwnedMonitorStackDepthInfo(this, thread, monitor_info_count_ptr, monitor_info_ptr); + } + + jvmtiError GetCurrentContendedMonitor(jthread thread, + jobject* monitor_ptr) { + return functions->GetCurrentContendedMonitor(this, thread, monitor_ptr); + } + + jvmtiError RunAgentThread(jthread thread, + jvmtiStartFunction proc, + const void* arg, + jint priority) { + return functions->RunAgentThread(this, thread, proc, arg, priority); + } + + jvmtiError SetThreadLocalStorage(jthread thread, + const void* data) { + return functions->SetThreadLocalStorage(this, thread, data); + } + + jvmtiError GetThreadLocalStorage(jthread thread, + void** data_ptr) { + return functions->GetThreadLocalStorage(this, thread, data_ptr); + } + + jvmtiError GetTopThreadGroups(jint* group_count_ptr, + jthreadGroup** groups_ptr) { + return functions->GetTopThreadGroups(this, group_count_ptr, groups_ptr); + } + + jvmtiError GetThreadGroupInfo(jthreadGroup group, + jvmtiThreadGroupInfo* info_ptr) { + return functions->GetThreadGroupInfo(this, group, info_ptr); + } + + jvmtiError GetThreadGroupChildren(jthreadGroup group, + jint* thread_count_ptr, + jthread** threads_ptr, + jint* group_count_ptr, + jthreadGroup** groups_ptr) { + return functions->GetThreadGroupChildren(this, group, thread_count_ptr, threads_ptr, group_count_ptr, groups_ptr); + } + + jvmtiError GetStackTrace(jthread thread, + jint start_depth, + jint max_frame_count, + jvmtiFrameInfo* frame_buffer, + jint* count_ptr) { + return functions->GetStackTrace(this, thread, start_depth, max_frame_count, frame_buffer, count_ptr); + } + + jvmtiError GetAllStackTraces(jint max_frame_count, + jvmtiStackInfo** stack_info_ptr, + jint* thread_count_ptr) { + return functions->GetAllStackTraces(this, max_frame_count, stack_info_ptr, thread_count_ptr); + } + + jvmtiError GetThreadListStackTraces(jint thread_count, + const jthread* thread_list, + jint max_frame_count, + jvmtiStackInfo** stack_info_ptr) { + return functions->GetThreadListStackTraces(this, thread_count, thread_list, max_frame_count, stack_info_ptr); + } + + jvmtiError GetFrameCount(jthread thread, + jint* count_ptr) { + return functions->GetFrameCount(this, thread, count_ptr); + } + + jvmtiError PopFrame(jthread thread) { + return functions->PopFrame(this, thread); + } + + jvmtiError GetFrameLocation(jthread thread, + jint depth, + jmethodID* method_ptr, + jlocation* location_ptr) { + return functions->GetFrameLocation(this, thread, depth, method_ptr, location_ptr); + } + + jvmtiError NotifyFramePop(jthread thread, + jint depth) { + return functions->NotifyFramePop(this, thread, depth); + } + + jvmtiError ForceEarlyReturnObject(jthread thread, + jobject value) { + return functions->ForceEarlyReturnObject(this, thread, value); + } + + jvmtiError ForceEarlyReturnInt(jthread thread, + jint value) { + return functions->ForceEarlyReturnInt(this, thread, value); + } + + jvmtiError ForceEarlyReturnLong(jthread thread, + jlong value) { + return functions->ForceEarlyReturnLong(this, thread, value); + } + + jvmtiError ForceEarlyReturnFloat(jthread thread, + jfloat value) { + return functions->ForceEarlyReturnFloat(this, thread, value); + } + + jvmtiError ForceEarlyReturnDouble(jthread thread, + jdouble value) { + return functions->ForceEarlyReturnDouble(this, thread, value); + } + + jvmtiError ForceEarlyReturnVoid(jthread thread) { + return functions->ForceEarlyReturnVoid(this, thread); + } + + jvmtiError FollowReferences(jint heap_filter, + jclass klass, + jobject initial_object, + const jvmtiHeapCallbacks* callbacks, + const void* user_data) { + return functions->FollowReferences(this, heap_filter, klass, initial_object, callbacks, user_data); + } + + jvmtiError IterateThroughHeap(jint heap_filter, + jclass klass, + const jvmtiHeapCallbacks* callbacks, + const void* user_data) { + return functions->IterateThroughHeap(this, heap_filter, klass, callbacks, user_data); + } + + jvmtiError GetTag(jobject object, + jlong* tag_ptr) { + return functions->GetTag(this, object, tag_ptr); + } + + jvmtiError SetTag(jobject object, + jlong tag) { + return functions->SetTag(this, object, tag); + } + + jvmtiError GetObjectsWithTags(jint tag_count, + const jlong* tags, + jint* count_ptr, + jobject** object_result_ptr, + jlong** tag_result_ptr) { + return functions->GetObjectsWithTags(this, tag_count, tags, count_ptr, object_result_ptr, tag_result_ptr); + } + + jvmtiError ForceGarbageCollection() { + return functions->ForceGarbageCollection(this); + } + + jvmtiError IterateOverObjectsReachableFromObject(jobject object, + jvmtiObjectReferenceCallback object_reference_callback, + const void* user_data) { + return functions->IterateOverObjectsReachableFromObject(this, object, object_reference_callback, user_data); + } + + jvmtiError IterateOverReachableObjects(jvmtiHeapRootCallback heap_root_callback, + jvmtiStackReferenceCallback stack_ref_callback, + jvmtiObjectReferenceCallback object_ref_callback, + const void* user_data) { + return functions->IterateOverReachableObjects(this, heap_root_callback, stack_ref_callback, object_ref_callback, user_data); + } + + jvmtiError IterateOverHeap(jvmtiHeapObjectFilter object_filter, + jvmtiHeapObjectCallback heap_object_callback, + const void* user_data) { + return functions->IterateOverHeap(this, object_filter, heap_object_callback, user_data); + } + + jvmtiError IterateOverInstancesOfClass(jclass klass, + jvmtiHeapObjectFilter object_filter, + jvmtiHeapObjectCallback heap_object_callback, + const void* user_data) { + return functions->IterateOverInstancesOfClass(this, klass, object_filter, heap_object_callback, user_data); + } + + jvmtiError GetLocalObject(jthread thread, + jint depth, + jint slot, + jobject* value_ptr) { + return functions->GetLocalObject(this, thread, depth, slot, value_ptr); + } + + jvmtiError GetLocalInstance(jthread thread, + jint depth, + jobject* value_ptr) { + return functions->GetLocalInstance(this, thread, depth, value_ptr); + } + + jvmtiError GetLocalInt(jthread thread, + jint depth, + jint slot, + jint* value_ptr) { + return functions->GetLocalInt(this, thread, depth, slot, value_ptr); + } + + jvmtiError GetLocalLong(jthread thread, + jint depth, + jint slot, + jlong* value_ptr) { + return functions->GetLocalLong(this, thread, depth, slot, value_ptr); + } + + jvmtiError GetLocalFloat(jthread thread, + jint depth, + jint slot, + jfloat* value_ptr) { + return functions->GetLocalFloat(this, thread, depth, slot, value_ptr); + } + + jvmtiError GetLocalDouble(jthread thread, + jint depth, + jint slot, + jdouble* value_ptr) { + return functions->GetLocalDouble(this, thread, depth, slot, value_ptr); + } + + jvmtiError SetLocalObject(jthread thread, + jint depth, + jint slot, + jobject value) { + return functions->SetLocalObject(this, thread, depth, slot, value); + } + + jvmtiError SetLocalInt(jthread thread, + jint depth, + jint slot, + jint value) { + return functions->SetLocalInt(this, thread, depth, slot, value); + } + + jvmtiError SetLocalLong(jthread thread, + jint depth, + jint slot, + jlong value) { + return functions->SetLocalLong(this, thread, depth, slot, value); + } + + jvmtiError SetLocalFloat(jthread thread, + jint depth, + jint slot, + jfloat value) { + return functions->SetLocalFloat(this, thread, depth, slot, value); + } + + jvmtiError SetLocalDouble(jthread thread, + jint depth, + jint slot, + jdouble value) { + return functions->SetLocalDouble(this, thread, depth, slot, value); + } + + jvmtiError SetBreakpoint(jmethodID method, + jlocation location) { + return functions->SetBreakpoint(this, method, location); + } + + jvmtiError ClearBreakpoint(jmethodID method, + jlocation location) { + return functions->ClearBreakpoint(this, method, location); + } + + jvmtiError SetFieldAccessWatch(jclass klass, + jfieldID field) { + return functions->SetFieldAccessWatch(this, klass, field); + } + + jvmtiError ClearFieldAccessWatch(jclass klass, + jfieldID field) { + return functions->ClearFieldAccessWatch(this, klass, field); + } + + jvmtiError SetFieldModificationWatch(jclass klass, + jfieldID field) { + return functions->SetFieldModificationWatch(this, klass, field); + } + + jvmtiError ClearFieldModificationWatch(jclass klass, + jfieldID field) { + return functions->ClearFieldModificationWatch(this, klass, field); + } + + jvmtiError GetLoadedClasses(jint* class_count_ptr, + jclass** classes_ptr) { + return functions->GetLoadedClasses(this, class_count_ptr, classes_ptr); + } + + jvmtiError GetClassLoaderClasses(jobject initiating_loader, + jint* class_count_ptr, + jclass** classes_ptr) { + return functions->GetClassLoaderClasses(this, initiating_loader, class_count_ptr, classes_ptr); + } + + jvmtiError GetClassSignature(jclass klass, + char** signature_ptr, + char** generic_ptr) { + return functions->GetClassSignature(this, klass, signature_ptr, generic_ptr); + } + + jvmtiError GetClassStatus(jclass klass, + jint* status_ptr) { + return functions->GetClassStatus(this, klass, status_ptr); + } + + jvmtiError GetSourceFileName(jclass klass, + char** source_name_ptr) { + return functions->GetSourceFileName(this, klass, source_name_ptr); + } + + jvmtiError GetClassModifiers(jclass klass, + jint* modifiers_ptr) { + return functions->GetClassModifiers(this, klass, modifiers_ptr); + } + + jvmtiError GetClassMethods(jclass klass, + jint* method_count_ptr, + jmethodID** methods_ptr) { + return functions->GetClassMethods(this, klass, method_count_ptr, methods_ptr); + } + + jvmtiError GetClassFields(jclass klass, + jint* field_count_ptr, + jfieldID** fields_ptr) { + return functions->GetClassFields(this, klass, field_count_ptr, fields_ptr); + } + + jvmtiError GetImplementedInterfaces(jclass klass, + jint* interface_count_ptr, + jclass** interfaces_ptr) { + return functions->GetImplementedInterfaces(this, klass, interface_count_ptr, interfaces_ptr); + } + + jvmtiError GetClassVersionNumbers(jclass klass, + jint* minor_version_ptr, + jint* major_version_ptr) { + return functions->GetClassVersionNumbers(this, klass, minor_version_ptr, major_version_ptr); + } + + jvmtiError GetConstantPool(jclass klass, + jint* constant_pool_count_ptr, + jint* constant_pool_byte_count_ptr, + unsigned char** constant_pool_bytes_ptr) { + return functions->GetConstantPool(this, klass, constant_pool_count_ptr, constant_pool_byte_count_ptr, constant_pool_bytes_ptr); + } + + jvmtiError IsInterface(jclass klass, + jboolean* is_interface_ptr) { + return functions->IsInterface(this, klass, is_interface_ptr); + } + + jvmtiError IsArrayClass(jclass klass, + jboolean* is_array_class_ptr) { + return functions->IsArrayClass(this, klass, is_array_class_ptr); + } + + jvmtiError IsModifiableClass(jclass klass, + jboolean* is_modifiable_class_ptr) { + return functions->IsModifiableClass(this, klass, is_modifiable_class_ptr); + } + + jvmtiError GetClassLoader(jclass klass, + jobject* classloader_ptr) { + return functions->GetClassLoader(this, klass, classloader_ptr); + } + + jvmtiError GetSourceDebugExtension(jclass klass, + char** source_debug_extension_ptr) { + return functions->GetSourceDebugExtension(this, klass, source_debug_extension_ptr); + } + + jvmtiError RetransformClasses(jint class_count, + const jclass* classes) { + return functions->RetransformClasses(this, class_count, classes); + } + + jvmtiError RedefineClasses(jint class_count, + const jvmtiClassDefinition* class_definitions) { + return functions->RedefineClasses(this, class_count, class_definitions); + } + + jvmtiError GetObjectSize(jobject object, + jlong* size_ptr) { + return functions->GetObjectSize(this, object, size_ptr); + } + + jvmtiError GetObjectHashCode(jobject object, + jint* hash_code_ptr) { + return functions->GetObjectHashCode(this, object, hash_code_ptr); + } + + jvmtiError GetObjectMonitorUsage(jobject object, + jvmtiMonitorUsage* info_ptr) { + return functions->GetObjectMonitorUsage(this, object, info_ptr); + } + + jvmtiError GetFieldName(jclass klass, + jfieldID field, + char** name_ptr, + char** signature_ptr, + char** generic_ptr) { + return functions->GetFieldName(this, klass, field, name_ptr, signature_ptr, generic_ptr); + } + + jvmtiError GetFieldDeclaringClass(jclass klass, + jfieldID field, + jclass* declaring_class_ptr) { + return functions->GetFieldDeclaringClass(this, klass, field, declaring_class_ptr); + } + + jvmtiError GetFieldModifiers(jclass klass, + jfieldID field, + jint* modifiers_ptr) { + return functions->GetFieldModifiers(this, klass, field, modifiers_ptr); + } + + jvmtiError IsFieldSynthetic(jclass klass, + jfieldID field, + jboolean* is_synthetic_ptr) { + return functions->IsFieldSynthetic(this, klass, field, is_synthetic_ptr); + } + + jvmtiError GetMethodName(jmethodID method, + char** name_ptr, + char** signature_ptr, + char** generic_ptr) { + return functions->GetMethodName(this, method, name_ptr, signature_ptr, generic_ptr); + } + + jvmtiError GetMethodDeclaringClass(jmethodID method, + jclass* declaring_class_ptr) { + return functions->GetMethodDeclaringClass(this, method, declaring_class_ptr); + } + + jvmtiError GetMethodModifiers(jmethodID method, + jint* modifiers_ptr) { + return functions->GetMethodModifiers(this, method, modifiers_ptr); + } + + jvmtiError GetMaxLocals(jmethodID method, + jint* max_ptr) { + return functions->GetMaxLocals(this, method, max_ptr); + } + + jvmtiError GetArgumentsSize(jmethodID method, + jint* size_ptr) { + return functions->GetArgumentsSize(this, method, size_ptr); + } + + jvmtiError GetLineNumberTable(jmethodID method, + jint* entry_count_ptr, + jvmtiLineNumberEntry** table_ptr) { + return functions->GetLineNumberTable(this, method, entry_count_ptr, table_ptr); + } + + jvmtiError GetMethodLocation(jmethodID method, + jlocation* start_location_ptr, + jlocation* end_location_ptr) { + return functions->GetMethodLocation(this, method, start_location_ptr, end_location_ptr); + } + + jvmtiError GetLocalVariableTable(jmethodID method, + jint* entry_count_ptr, + jvmtiLocalVariableEntry** table_ptr) { + return functions->GetLocalVariableTable(this, method, entry_count_ptr, table_ptr); + } + + jvmtiError GetBytecodes(jmethodID method, + jint* bytecode_count_ptr, + unsigned char** bytecodes_ptr) { + return functions->GetBytecodes(this, method, bytecode_count_ptr, bytecodes_ptr); + } + + jvmtiError IsMethodNative(jmethodID method, + jboolean* is_native_ptr) { + return functions->IsMethodNative(this, method, is_native_ptr); + } + + jvmtiError IsMethodSynthetic(jmethodID method, + jboolean* is_synthetic_ptr) { + return functions->IsMethodSynthetic(this, method, is_synthetic_ptr); + } + + jvmtiError IsMethodObsolete(jmethodID method, + jboolean* is_obsolete_ptr) { + return functions->IsMethodObsolete(this, method, is_obsolete_ptr); + } + + jvmtiError SetNativeMethodPrefix(const char* prefix) { + return functions->SetNativeMethodPrefix(this, prefix); + } + + jvmtiError SetNativeMethodPrefixes(jint prefix_count, + char** prefixes) { + return functions->SetNativeMethodPrefixes(this, prefix_count, prefixes); + } + + jvmtiError CreateRawMonitor(const char* name, + jrawMonitorID* monitor_ptr) { + return functions->CreateRawMonitor(this, name, monitor_ptr); + } + + jvmtiError DestroyRawMonitor(jrawMonitorID monitor) { + return functions->DestroyRawMonitor(this, monitor); + } + + jvmtiError RawMonitorEnter(jrawMonitorID monitor) { + return functions->RawMonitorEnter(this, monitor); + } + + jvmtiError RawMonitorExit(jrawMonitorID monitor) { + return functions->RawMonitorExit(this, monitor); + } + + jvmtiError RawMonitorWait(jrawMonitorID monitor, + jlong millis) { + return functions->RawMonitorWait(this, monitor, millis); + } + + jvmtiError RawMonitorNotify(jrawMonitorID monitor) { + return functions->RawMonitorNotify(this, monitor); + } + + jvmtiError RawMonitorNotifyAll(jrawMonitorID monitor) { + return functions->RawMonitorNotifyAll(this, monitor); + } + + jvmtiError SetJNIFunctionTable(const jniNativeInterface* function_table) { + return functions->SetJNIFunctionTable(this, function_table); + } + + jvmtiError GetJNIFunctionTable(jniNativeInterface** function_table) { + return functions->GetJNIFunctionTable(this, function_table); + } + + jvmtiError SetEventCallbacks(const jvmtiEventCallbacks* callbacks, + jint size_of_callbacks) { + return functions->SetEventCallbacks(this, callbacks, size_of_callbacks); + } + + jvmtiError SetEventNotificationMode(jvmtiEventMode mode, + jvmtiEvent event_type, + jthread event_thread, + ...) { + return functions->SetEventNotificationMode(this, mode, event_type, event_thread); + } + + jvmtiError GenerateEvents(jvmtiEvent event_type) { + return functions->GenerateEvents(this, event_type); + } + + jvmtiError GetExtensionFunctions(jint* extension_count_ptr, + jvmtiExtensionFunctionInfo** extensions) { + return functions->GetExtensionFunctions(this, extension_count_ptr, extensions); + } + + jvmtiError GetExtensionEvents(jint* extension_count_ptr, + jvmtiExtensionEventInfo** extensions) { + return functions->GetExtensionEvents(this, extension_count_ptr, extensions); + } + + jvmtiError SetExtensionEventCallback(jint extension_event_index, + jvmtiExtensionEvent callback) { + return functions->SetExtensionEventCallback(this, extension_event_index, callback); + } + + jvmtiError GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) { + return functions->GetPotentialCapabilities(this, capabilities_ptr); + } + + jvmtiError AddCapabilities(const jvmtiCapabilities* capabilities_ptr) { + return functions->AddCapabilities(this, capabilities_ptr); + } + + jvmtiError RelinquishCapabilities(const jvmtiCapabilities* capabilities_ptr) { + return functions->RelinquishCapabilities(this, capabilities_ptr); + } + + jvmtiError GetCapabilities(jvmtiCapabilities* capabilities_ptr) { + return functions->GetCapabilities(this, capabilities_ptr); + } + + jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) { + return functions->GetCurrentThreadCpuTimerInfo(this, info_ptr); + } + + jvmtiError GetCurrentThreadCpuTime(jlong* nanos_ptr) { + return functions->GetCurrentThreadCpuTime(this, nanos_ptr); + } + + jvmtiError GetThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) { + return functions->GetThreadCpuTimerInfo(this, info_ptr); + } + + jvmtiError GetThreadCpuTime(jthread thread, + jlong* nanos_ptr) { + return functions->GetThreadCpuTime(this, thread, nanos_ptr); + } + + jvmtiError GetTimerInfo(jvmtiTimerInfo* info_ptr) { + return functions->GetTimerInfo(this, info_ptr); + } + + jvmtiError GetTime(jlong* nanos_ptr) { + return functions->GetTime(this, nanos_ptr); + } + + jvmtiError GetAvailableProcessors(jint* processor_count_ptr) { + return functions->GetAvailableProcessors(this, processor_count_ptr); + } + + jvmtiError AddToBootstrapClassLoaderSearch(const char* segment) { + return functions->AddToBootstrapClassLoaderSearch(this, segment); + } + + jvmtiError AddToSystemClassLoaderSearch(const char* segment) { + return functions->AddToSystemClassLoaderSearch(this, segment); + } + + jvmtiError GetSystemProperties(jint* count_ptr, + char*** property_ptr) { + return functions->GetSystemProperties(this, count_ptr, property_ptr); + } + + jvmtiError GetSystemProperty(const char* property, + char** value_ptr) { + return functions->GetSystemProperty(this, property, value_ptr); + } + + jvmtiError SetSystemProperty(const char* property, + const char* value) { + return functions->SetSystemProperty(this, property, value); + } + + jvmtiError GetPhase(jvmtiPhase* phase_ptr) { + return functions->GetPhase(this, phase_ptr); + } + + jvmtiError DisposeEnvironment() { + return functions->DisposeEnvironment(this); + } + + jvmtiError SetEnvironmentLocalStorage(const void* data) { + return functions->SetEnvironmentLocalStorage(this, data); + } + + jvmtiError GetEnvironmentLocalStorage(void** data_ptr) { + return functions->GetEnvironmentLocalStorage(this, data_ptr); + } + + jvmtiError GetVersionNumber(jint* version_ptr) { + return functions->GetVersionNumber(this, version_ptr); + } + + jvmtiError GetErrorName(jvmtiError error, + char** name_ptr) { + return functions->GetErrorName(this, error, name_ptr); + } + + jvmtiError SetVerboseFlag(jvmtiVerboseFlag flag, + jboolean value) { + return functions->SetVerboseFlag(this, flag, value); + } + + jvmtiError GetJLocationFormat(jvmtiJlocationFormat* format_ptr) { + return functions->GetJLocationFormat(this, format_ptr); + } + +#endif /* __cplusplus */ +}; + + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* !_JAVA_JVMTI_H_ */ + diff --git a/arthas-vmtool/src/main/native/head/jvmticmlr.h b/arthas-vmtool/src/main/native/head/jvmticmlr.h new file mode 100755 index 000000000..a9c88f36e --- /dev/null +++ b/arthas-vmtool/src/main/native/head/jvmticmlr.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * This header file defines the data structures sent by the VM + * through the JVMTI CompiledMethodLoad callback function via the + * "void * compile_info" parameter. The memory pointed to by the + * compile_info parameter may not be referenced after returning from + * the CompiledMethodLoad callback. These are VM implementation + * specific data structures that may evolve in future releases. A + * JVMTI agent should interpret a non-NULL compile_info as a pointer + * to a region of memory containing a list of records. In a typical + * usage scenario, a JVMTI agent would cast each record to a + * jvmtiCompiledMethodLoadRecordHeader, a struct that represents + * arbitrary information. This struct contains a kind field to indicate + * the kind of information being passed, and a pointer to the next + * record. If the kind field indicates inlining information, then the + * agent would cast the record to a jvmtiCompiledMethodLoadInlineRecord. + * This record contains an array of PCStackInfo structs, which indicate + * for every pc address what are the methods on the invocation stack. + * The "methods" and "bcis" fields in each PCStackInfo struct specify a + * 1-1 mapping between these inlined methods and their bytecode indices. + * This can be used to derive the proper source lines of the inlined + * methods. + */ + +#ifndef _JVMTI_CMLR_H_ +#define _JVMTI_CMLR_H_ + +enum { + JVMTI_CMLR_MAJOR_VERSION_1 = 0x00000001, + JVMTI_CMLR_MINOR_VERSION_0 = 0x00000000, + + JVMTI_CMLR_MAJOR_VERSION = 0x00000001, + JVMTI_CMLR_MINOR_VERSION = 0x00000000 + + /* + * This comment is for the "JDK import from HotSpot" sanity check: + * version: 1.0.0 + */ +}; + +typedef enum { + JVMTI_CMLR_DUMMY = 1, + JVMTI_CMLR_INLINE_INFO = 2 +} jvmtiCMLRKind; + +/* + * Record that represents arbitrary information passed through JVMTI + * CompiledMethodLoadEvent void pointer. + */ +typedef struct _jvmtiCompiledMethodLoadRecordHeader { + jvmtiCMLRKind kind; /* id for the kind of info passed in the record */ + jint majorinfoversion; /* major and minor info version values. Init'ed */ + jint minorinfoversion; /* to current version value in jvmtiExport.cpp. */ + + struct _jvmtiCompiledMethodLoadRecordHeader* next; +} jvmtiCompiledMethodLoadRecordHeader; + +/* + * Record that gives information about the methods on the compile-time + * stack at a specific pc address of a compiled method. Each element in + * the methods array maps to same element in the bcis array. + */ +typedef struct _PCStackInfo { + void* pc; /* the pc address for this compiled method */ + jint numstackframes; /* number of methods on the stack */ + jmethodID* methods; /* array of numstackframes method ids */ + jint* bcis; /* array of numstackframes bytecode indices */ +} PCStackInfo; + +/* + * Record that contains inlining information for each pc address of + * an nmethod. + */ +typedef struct _jvmtiCompiledMethodLoadInlineRecord { + jvmtiCompiledMethodLoadRecordHeader header; /* common header for casting */ + jint numpcs; /* number of pc descriptors in this nmethod */ + PCStackInfo* pcinfo; /* array of numpcs pc descriptors */ +} jvmtiCompiledMethodLoadInlineRecord; + +/* + * Dummy record used to test that we can pass records with different + * information through the void pointer provided that they can be cast + * to a jvmtiCompiledMethodLoadRecordHeader. + */ + +typedef struct _jvmtiCompiledMethodLoadDummyRecord { + jvmtiCompiledMethodLoadRecordHeader header; /* common header for casting */ + char message[50]; +} jvmtiCompiledMethodLoadDummyRecord; + +#endif diff --git a/arthas-vmtool/src/main/native/head/linux/jawt_md.h b/arthas-vmtool/src/main/native/head/linux/jawt_md.h new file mode 100644 index 000000000..825142ca8 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/linux/jawt_md.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JAWT_MD_H_ +#define _JAVASOFT_JAWT_MD_H_ + +#include +#include +#include +#include "jawt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * X11-specific declarations for AWT native interface. + * See notes in jawt.h for an example of use. + */ +typedef struct jawt_X11DrawingSurfaceInfo { + Drawable drawable; + Display* display; + VisualID visualID; + Colormap colormapID; + int depth; + /* + * Since 1.4 + * Returns a pixel value from a set of RGB values. + * This is useful for paletted color (256 color) modes. + */ + int (JNICALL *GetAWTColor)(JAWT_DrawingSurface* ds, + int r, int g, int b); +} JAWT_X11DrawingSurfaceInfo; + +#ifdef __cplusplus +} +#endif + +#endif /* !_JAVASOFT_JAWT_MD_H_ */ diff --git a/arthas-vmtool/src/main/native/head/linux/jni_md.h b/arthas-vmtool/src/main/native/head/linux/jni_md.h new file mode 100644 index 000000000..ff30a32c3 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/linux/jni_md.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JNI_MD_H_ +#define _JAVASOFT_JNI_MD_H_ + +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#if (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))) || __has_attribute(visibility) + #define JNIEXPORT __attribute__((visibility("default"))) + #define JNIIMPORT __attribute__((visibility("default"))) +#else + #define JNIEXPORT + #define JNIIMPORT +#endif + +#define JNICALL + +typedef int jint; +#ifdef _LP64 /* 64-bit Solaris */ +typedef long jlong; +#else +typedef long long jlong; +#endif + +typedef signed char jbyte; + +#endif /* !_JAVASOFT_JNI_MD_H_ */ diff --git a/arthas-vmtool/src/main/native/head/macos/jawt_md.h b/arthas-vmtool/src/main/native/head/macos/jawt_md.h new file mode 100644 index 000000000..d803a0f7f --- /dev/null +++ b/arthas-vmtool/src/main/native/head/macos/jawt_md.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JAWT_MD_H_ +#define _JAVASOFT_JAWT_MD_H_ + +#include "jawt.h" + +#ifdef __OBJC__ +#import +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Mac OS X specific declarations for AWT native interface. + * See notes in jawt.h for an example of use. + */ + +/* + * When calling JAWT_GetAWT with a JAWT version less than 1.7, you must pass this + * flag or you will not be able to get a valid drawing surface and JAWT_GetAWT will + * return false. This is to maintain compatibility with applications that used the + * interface with Java 6 which had multiple rendering models. This flag is not necessary + * when JAWT version 1.7 or greater is used as this is the only supported rendering mode. + * + * Example: + * JAWT awt; + * awt.version = JAWT_VERSION_1_4 | JAWT_MACOSX_USE_CALAYER; + * jboolean success = JAWT_GetAWT(env, &awt); + */ +#define JAWT_MACOSX_USE_CALAYER 0x80000000 + +/* + * When the native Cocoa toolkit is in use, the pointer stored in + * JAWT_DrawingSurfaceInfo->platformInfo points to a NSObject that conforms to the + * JAWT_SurfaceLayers protocol. Setting the layer property of this object will cause the + * specified layer to be overlaid on the Components rectangle. If the window the + * Component belongs to has a CALayer attached to it, this layer will be accessible via + * the windowLayer property. + */ +#ifdef __OBJC__ +@protocol JAWT_SurfaceLayers +@property (readwrite, retain) CALayer *layer; +@property (readonly) CALayer *windowLayer; +@end +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* !_JAVASOFT_JAWT_MD_H_ */ diff --git a/arthas-vmtool/src/main/native/head/macos/jni_md.h b/arthas-vmtool/src/main/native/head/macos/jni_md.h new file mode 100644 index 000000000..d2b83307f --- /dev/null +++ b/arthas-vmtool/src/main/native/head/macos/jni_md.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JNI_MD_H_ +#define _JAVASOFT_JNI_MD_H_ + +#define JNIEXPORT __attribute__((visibility("default"))) +#define JNIIMPORT __attribute__((visibility("default"))) +#define JNICALL + +typedef int jint; +#ifdef _LP64 /* 64-bit */ +typedef long jlong; +#else +typedef long long jlong; +#endif + +typedef signed char jbyte; + +#endif /* !_JAVASOFT_JNI_MD_H_ */ diff --git a/arthas-vmtool/src/main/native/head/windows/AccessBridgeCallbacks.h b/arthas-vmtool/src/main/native/head/windows/AccessBridgeCallbacks.h new file mode 100755 index 000000000..df5035b84 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/windows/AccessBridgeCallbacks.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * AccessBridgeCallbacks.h 1.17 05/03/21 + */ + +/* + * Header file defining callback typedefs for Windows routines + * which are called from Java (responding to events, etc.). + */ + +#ifndef __AccessBridgeCallbacks_H__ +#define __AccessBridgeCallbacks_H__ + +#include +#include "AccessBridgePackages.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*AccessBridge_PropertyChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + wchar_t *property, wchar_t *oldValue, wchar_t *newValue); + +typedef void (*AccessBridge_JavaShutdownFP) (long vmID); +typedef void (*AccessBridge_JavaShutdownFP) (long vmID); + +typedef void (*AccessBridge_FocusGainedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_FocusLostFP) (long vmID, JOBJECT64 event, JOBJECT64 source); + +typedef void (*AccessBridge_CaretUpdateFP) (long vmID, JOBJECT64 event, JOBJECT64 source); + +typedef void (*AccessBridge_MouseClickedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_MouseEnteredFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_MouseExitedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_MousePressedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_MouseReleasedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); + +typedef void (*AccessBridge_MenuCanceledFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_MenuDeselectedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_MenuSelectedFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_PopupMenuCanceledFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_PopupMenuWillBecomeInvisibleFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_PopupMenuWillBecomeVisibleFP) (long vmID, JOBJECT64 event, JOBJECT64 source); + +typedef void (*AccessBridge_PropertyNameChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + wchar_t *oldName, wchar_t *newName); +typedef void (*AccessBridge_PropertyDescriptionChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + wchar_t *oldDescription, wchar_t *newDescription); +typedef void (*AccessBridge_PropertyStateChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + wchar_t *oldState, wchar_t *newState); +typedef void (*AccessBridge_PropertyValueChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + wchar_t *oldValue, wchar_t *newValue); +typedef void (*AccessBridge_PropertySelectionChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_PropertyTextChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_PropertyCaretChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + int oldPosition, int newPosition); +typedef void (*AccessBridge_PropertyVisibleDataChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source); +typedef void (*AccessBridge_PropertyChildChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 source, + JOBJECT64 oldChild, JOBJECT64 newChild); +typedef void (*AccessBridge_PropertyActiveDescendentChangeFP) (long vmID, JOBJECT64 event, + JOBJECT64 source, + JOBJECT64 oldActiveDescendent, + JOBJECT64 newActiveDescendent); + +typedef void (*AccessBridge_PropertyTableModelChangeFP) (long vmID, JOBJECT64 event, JOBJECT64 src, + wchar_t *oldValue, wchar_t *newValue); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/arthas-vmtool/src/main/native/head/windows/AccessBridgeCalls.c b/arthas-vmtool/src/main/native/head/windows/AccessBridgeCalls.c new file mode 100755 index 000000000..368664818 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/windows/AccessBridgeCalls.c @@ -0,0 +1,1131 @@ +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * @(#)AccessBridgeCalls.c 1.25 05/08/22 + */ + +/* + * Wrapper functions around calls to the AccessBridge DLL + */ + + +#include +#include + + +//#define ACCESSBRIDGE_32 +//#define ACCESSBRIDGE_64 + +#include "AccessBridgeCalls.h" +#include "AccessBridgeDebug.h" + +#ifdef __cplusplus +extern "C" { +#endif + + HINSTANCE theAccessBridgeInstance; + AccessBridgeFPs theAccessBridge; + + BOOL theAccessBridgeInitializedFlag = FALSE; + +#define LOAD_FP(result, type, name) \ + PrintDebugString("LOAD_FP loading: %s ...", name); \ + if ((theAccessBridge.result = \ + (type) GetProcAddress(theAccessBridgeInstance, name)) == (type) 0) { \ + PrintDebugString("LOAD_FP failed: %s", name); \ + return FALSE; \ + } + + BOOL initializeAccessBridge() { + +#ifdef ACCESSBRIDGE_ARCH_32 // For 32bit AT new bridge + theAccessBridgeInstance = LoadLibrary("WINDOWSACCESSBRIDGE-32"); +#else +#ifdef ACCESSBRIDGE_ARCH_64 // For 64bit AT new bridge + theAccessBridgeInstance = LoadLibrary("WINDOWSACCESSBRIDGE-64"); +#else // legacy + theAccessBridgeInstance = LoadLibrary("WINDOWSACCESSBRIDGE"); +#endif +#endif + if (theAccessBridgeInstance != 0) { + LOAD_FP(Windows_run, Windows_runFP, "Windows_run"); + + LOAD_FP(SetJavaShutdown, SetJavaShutdownFP, "setJavaShutdownFP"); + LOAD_FP(SetFocusGained, SetFocusGainedFP, "setFocusGainedFP"); + LOAD_FP(SetFocusLost, SetFocusLostFP, "setFocusLostFP"); + + LOAD_FP(SetCaretUpdate, SetCaretUpdateFP, "setCaretUpdateFP"); + + LOAD_FP(SetMouseClicked, SetMouseClickedFP, "setMouseClickedFP"); + LOAD_FP(SetMouseEntered, SetMouseEnteredFP, "setMouseEnteredFP"); + LOAD_FP(SetMouseExited, SetMouseExitedFP, "setMouseExitedFP"); + LOAD_FP(SetMousePressed, SetMousePressedFP, "setMousePressedFP"); + LOAD_FP(SetMouseReleased, SetMouseReleasedFP, "setMouseReleasedFP"); + + LOAD_FP(SetMenuCanceled, SetMenuCanceledFP, "setMenuCanceledFP"); + LOAD_FP(SetMenuDeselected, SetMenuDeselectedFP, "setMenuDeselectedFP"); + LOAD_FP(SetMenuSelected, SetMenuSelectedFP, "setMenuSelectedFP"); + LOAD_FP(SetPopupMenuCanceled, SetPopupMenuCanceledFP, "setPopupMenuCanceledFP"); + LOAD_FP(SetPopupMenuWillBecomeInvisible, SetPopupMenuWillBecomeInvisibleFP, "setPopupMenuWillBecomeInvisibleFP"); + LOAD_FP(SetPopupMenuWillBecomeVisible, SetPopupMenuWillBecomeVisibleFP, "setPopupMenuWillBecomeVisibleFP"); + + LOAD_FP(SetPropertyNameChange, SetPropertyNameChangeFP, "setPropertyNameChangeFP"); + LOAD_FP(SetPropertyDescriptionChange, SetPropertyDescriptionChangeFP, "setPropertyDescriptionChangeFP"); + LOAD_FP(SetPropertyStateChange, SetPropertyStateChangeFP, "setPropertyStateChangeFP"); + LOAD_FP(SetPropertyValueChange, SetPropertyValueChangeFP, "setPropertyValueChangeFP"); + LOAD_FP(SetPropertySelectionChange, SetPropertySelectionChangeFP, "setPropertySelectionChangeFP"); + LOAD_FP(SetPropertyTextChange, SetPropertyTextChangeFP, "setPropertyTextChangeFP"); + LOAD_FP(SetPropertyCaretChange, SetPropertyCaretChangeFP, "setPropertyCaretChangeFP"); + LOAD_FP(SetPropertyVisibleDataChange, SetPropertyVisibleDataChangeFP, "setPropertyVisibleDataChangeFP"); + LOAD_FP(SetPropertyChildChange, SetPropertyChildChangeFP, "setPropertyChildChangeFP"); + LOAD_FP(SetPropertyActiveDescendentChange, SetPropertyActiveDescendentChangeFP, "setPropertyActiveDescendentChangeFP"); + + LOAD_FP(SetPropertyTableModelChange, SetPropertyTableModelChangeFP, "setPropertyTableModelChangeFP"); + + LOAD_FP(ReleaseJavaObject, ReleaseJavaObjectFP, "releaseJavaObject"); + LOAD_FP(GetVersionInfo, GetVersionInfoFP, "getVersionInfo"); + + LOAD_FP(IsJavaWindow, IsJavaWindowFP, "isJavaWindow"); + LOAD_FP(IsSameObject, IsSameObjectFP, "isSameObject"); + LOAD_FP(GetAccessibleContextFromHWND, GetAccessibleContextFromHWNDFP, "getAccessibleContextFromHWND"); + LOAD_FP(getHWNDFromAccessibleContext, getHWNDFromAccessibleContextFP, "getHWNDFromAccessibleContext"); + + LOAD_FP(GetAccessibleContextAt, GetAccessibleContextAtFP, "getAccessibleContextAt"); + LOAD_FP(GetAccessibleContextWithFocus, GetAccessibleContextWithFocusFP, "getAccessibleContextWithFocus"); + LOAD_FP(GetAccessibleContextInfo, GetAccessibleContextInfoFP, "getAccessibleContextInfo"); + LOAD_FP(GetAccessibleChildFromContext, GetAccessibleChildFromContextFP, "getAccessibleChildFromContext"); + LOAD_FP(GetAccessibleParentFromContext, GetAccessibleParentFromContextFP, "getAccessibleParentFromContext"); + + /* begin AccessibleTable */ + LOAD_FP(getAccessibleTableInfo, getAccessibleTableInfoFP, "getAccessibleTableInfo"); + LOAD_FP(getAccessibleTableCellInfo, getAccessibleTableCellInfoFP, "getAccessibleTableCellInfo"); + + LOAD_FP(getAccessibleTableRowHeader, getAccessibleTableRowHeaderFP, "getAccessibleTableRowHeader"); + LOAD_FP(getAccessibleTableColumnHeader, getAccessibleTableColumnHeaderFP, "getAccessibleTableColumnHeader"); + + LOAD_FP(getAccessibleTableRowDescription, getAccessibleTableRowDescriptionFP, "getAccessibleTableRowDescription"); + LOAD_FP(getAccessibleTableColumnDescription, getAccessibleTableColumnDescriptionFP, "getAccessibleTableColumnDescription"); + + LOAD_FP(getAccessibleTableRowSelectionCount, getAccessibleTableRowSelectionCountFP, + "getAccessibleTableRowSelectionCount"); + LOAD_FP(isAccessibleTableRowSelected, isAccessibleTableRowSelectedFP, + "isAccessibleTableRowSelected"); + LOAD_FP(getAccessibleTableRowSelections, getAccessibleTableRowSelectionsFP, + "getAccessibleTableRowSelections"); + + LOAD_FP(getAccessibleTableColumnSelectionCount, getAccessibleTableColumnSelectionCountFP, + "getAccessibleTableColumnSelectionCount"); + LOAD_FP(isAccessibleTableColumnSelected, isAccessibleTableColumnSelectedFP, + "isAccessibleTableColumnSelected"); + LOAD_FP(getAccessibleTableColumnSelections, getAccessibleTableColumnSelectionsFP, + "getAccessibleTableColumnSelections"); + + LOAD_FP(getAccessibleTableRow, getAccessibleTableRowFP, + "getAccessibleTableRow"); + LOAD_FP(getAccessibleTableColumn, getAccessibleTableColumnFP, + "getAccessibleTableColumn"); + LOAD_FP(getAccessibleTableIndex, getAccessibleTableIndexFP, + "getAccessibleTableIndex"); + + /* end AccessibleTable */ + + /* AccessibleRelationSet */ + LOAD_FP(getAccessibleRelationSet, getAccessibleRelationSetFP, "getAccessibleRelationSet"); + + /* AccessibleHypertext */ + LOAD_FP(getAccessibleHypertext, getAccessibleHypertextFP, "getAccessibleHypertext"); + LOAD_FP(activateAccessibleHyperlink, activateAccessibleHyperlinkFP, "activateAccessibleHyperlink"); + LOAD_FP(getAccessibleHyperlinkCount, getAccessibleHyperlinkCountFP, "getAccessibleHyperlinkCount"); + LOAD_FP(getAccessibleHypertextExt, getAccessibleHypertextExtFP, "getAccessibleHypertextExt"); + LOAD_FP(getAccessibleHypertextLinkIndex, getAccessibleHypertextLinkIndexFP, "getAccessibleHypertextLinkIndex"); + LOAD_FP(getAccessibleHyperlink, getAccessibleHyperlinkFP, "getAccessibleHyperlink"); + + /* Accessible KeyBinding, Icon and Action */ + LOAD_FP(getAccessibleKeyBindings, getAccessibleKeyBindingsFP, "getAccessibleKeyBindings"); + LOAD_FP(getAccessibleIcons, getAccessibleIconsFP, "getAccessibleIcons"); + LOAD_FP(getAccessibleActions, getAccessibleActionsFP, "getAccessibleActions"); + LOAD_FP(doAccessibleActions, doAccessibleActionsFP, "doAccessibleActions"); + + /* AccessibleText */ + LOAD_FP(GetAccessibleTextInfo, GetAccessibleTextInfoFP, "getAccessibleTextInfo"); + LOAD_FP(GetAccessibleTextItems, GetAccessibleTextItemsFP, "getAccessibleTextItems"); + LOAD_FP(GetAccessibleTextSelectionInfo, GetAccessibleTextSelectionInfoFP, "getAccessibleTextSelectionInfo"); + LOAD_FP(GetAccessibleTextAttributes, GetAccessibleTextAttributesFP, "getAccessibleTextAttributes"); + LOAD_FP(GetAccessibleTextRect, GetAccessibleTextRectFP, "getAccessibleTextRect"); + LOAD_FP(GetAccessibleTextLineBounds, GetAccessibleTextLineBoundsFP, "getAccessibleTextLineBounds"); + LOAD_FP(GetAccessibleTextRange, GetAccessibleTextRangeFP, "getAccessibleTextRange"); + + LOAD_FP(GetCurrentAccessibleValueFromContext, GetCurrentAccessibleValueFromContextFP, "getCurrentAccessibleValueFromContext"); + LOAD_FP(GetMaximumAccessibleValueFromContext, GetMaximumAccessibleValueFromContextFP, "getMaximumAccessibleValueFromContext"); + LOAD_FP(GetMinimumAccessibleValueFromContext, GetMinimumAccessibleValueFromContextFP, "getMinimumAccessibleValueFromContext"); + + LOAD_FP(AddAccessibleSelectionFromContext, AddAccessibleSelectionFromContextFP, "addAccessibleSelectionFromContext"); + LOAD_FP(ClearAccessibleSelectionFromContext, ClearAccessibleSelectionFromContextFP, "clearAccessibleSelectionFromContext"); + LOAD_FP(GetAccessibleSelectionFromContext, GetAccessibleSelectionFromContextFP, "getAccessibleSelectionFromContext"); + LOAD_FP(GetAccessibleSelectionCountFromContext, GetAccessibleSelectionCountFromContextFP, "getAccessibleSelectionCountFromContext"); + LOAD_FP(IsAccessibleChildSelectedFromContext, IsAccessibleChildSelectedFromContextFP, "isAccessibleChildSelectedFromContext"); + LOAD_FP(RemoveAccessibleSelectionFromContext, RemoveAccessibleSelectionFromContextFP, "removeAccessibleSelectionFromContext"); + LOAD_FP(SelectAllAccessibleSelectionFromContext, SelectAllAccessibleSelectionFromContextFP, "selectAllAccessibleSelectionFromContext"); + + LOAD_FP(setTextContents, setTextContentsFP, "setTextContents"); + LOAD_FP(getParentWithRole, getParentWithRoleFP, "getParentWithRole"); + LOAD_FP(getTopLevelObject, getTopLevelObjectFP, "getTopLevelObject"); + LOAD_FP(getParentWithRoleElseRoot, getParentWithRoleElseRootFP, "getParentWithRoleElseRoot"); + LOAD_FP(getObjectDepth, getObjectDepthFP, "getObjectDepth"); + LOAD_FP(getActiveDescendent, getActiveDescendentFP, "getActiveDescendent"); + + // additional methods for Teton + LOAD_FP(getVirtualAccessibleName, getVirtualAccessibleNameFP, "getVirtualAccessibleName"); + LOAD_FP(requestFocus, requestFocusFP, "requestFocus"); + LOAD_FP(selectTextRange, selectTextRangeFP, "selectTextRange"); + LOAD_FP(getTextAttributesInRange, getTextAttributesInRangeFP, "getTextAttributesInRange"); + LOAD_FP(getVisibleChildrenCount, getVisibleChildrenCountFP, "getVisibleChildrenCount"); + LOAD_FP(getVisibleChildren, getVisibleChildrenFP, "getVisibleChildren"); + LOAD_FP(setCaretPosition, setCaretPositionFP, "setCaretPosition"); + LOAD_FP(getCaretLocation, getCaretLocationFP, "getCaretLocation"); + + LOAD_FP(getEventsWaiting, getEventsWaitingFP, "getEventsWaiting"); + + theAccessBridge.Windows_run(); + + theAccessBridgeInitializedFlag = TRUE; + PrintDebugString("theAccessBridgeInitializedFlag = TRUE"); + return TRUE; + } else { + return FALSE; + } + } + + + BOOL shutdownAccessBridge() { + BOOL result; + DWORD error; + theAccessBridgeInitializedFlag = FALSE; + if (theAccessBridgeInstance != (HANDLE) 0) { + result = FreeLibrary(theAccessBridgeInstance); + if (result != TRUE) { + error = GetLastError(); + } + return TRUE; + } + return FALSE; + } + + + void SetJavaShutdown(AccessBridge_JavaShutdownFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetJavaShutdown(fp); + } + } + + void SetFocusGained(AccessBridge_FocusGainedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetFocusGained(fp); + } + } + + void SetFocusLost(AccessBridge_FocusLostFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetFocusLost(fp); + } + } + + + void SetCaretUpdate(AccessBridge_CaretUpdateFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetCaretUpdate(fp); + } + } + + + void SetMouseClicked(AccessBridge_MouseClickedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMouseClicked(fp); + } + } + + void SetMouseEntered(AccessBridge_MouseEnteredFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMouseEntered(fp); + } + } + + void SetMouseExited(AccessBridge_MouseExitedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMouseExited(fp); + } + } + + void SetMousePressed(AccessBridge_MousePressedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMousePressed(fp); + } + } + + void SetMouseReleased(AccessBridge_MouseReleasedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMouseReleased(fp); + } + } + + + void SetMenuCanceled(AccessBridge_MenuCanceledFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMenuCanceled(fp); + } + } + + void SetMenuDeselected(AccessBridge_MenuDeselectedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMenuDeselected(fp); + } + } + + void SetMenuSelected(AccessBridge_MenuSelectedFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetMenuSelected(fp); + } + } + + void SetPopupMenuCanceled(AccessBridge_PopupMenuCanceledFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPopupMenuCanceled(fp); + } + } + + void SetPopupMenuWillBecomeInvisible(AccessBridge_PopupMenuWillBecomeInvisibleFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPopupMenuWillBecomeInvisible(fp); + } + } + + void SetPopupMenuWillBecomeVisible(AccessBridge_PopupMenuWillBecomeVisibleFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPopupMenuWillBecomeVisible(fp); + } + } + + + void SetPropertyNameChange(AccessBridge_PropertyNameChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyNameChange(fp); + } + } + + void SetPropertyDescriptionChange(AccessBridge_PropertyDescriptionChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyDescriptionChange(fp); + } + } + + void SetPropertyStateChange(AccessBridge_PropertyStateChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyStateChange(fp); + } + } + + void SetPropertyValueChange(AccessBridge_PropertyValueChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyValueChange(fp); + } + } + + void SetPropertySelectionChange(AccessBridge_PropertySelectionChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertySelectionChange(fp); + } + } + + void SetPropertyTextChange(AccessBridge_PropertyTextChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyTextChange(fp); + } + } + + void SetPropertyCaretChange(AccessBridge_PropertyCaretChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyCaretChange(fp); + } + } + + void SetPropertyVisibleDataChange(AccessBridge_PropertyVisibleDataChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyVisibleDataChange(fp); + } + } + + void SetPropertyChildChange(AccessBridge_PropertyChildChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyChildChange(fp); + } + } + + void SetPropertyActiveDescendentChange(AccessBridge_PropertyActiveDescendentChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyActiveDescendentChange(fp); + } + } + + void SetPropertyTableModelChange(AccessBridge_PropertyTableModelChangeFP fp) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SetPropertyTableModelChange(fp); + } + } + + /** + * General routines + */ + void ReleaseJavaObject(long vmID, Java_Object object) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.ReleaseJavaObject(vmID, object); + } + } + + BOOL GetVersionInfo(long vmID, AccessBridgeVersionInfo *info) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetVersionInfo(vmID, info); + } + return FALSE; + } + + + /** + * Window routines + */ + BOOL IsJavaWindow(HWND window) { + if (theAccessBridgeInitializedFlag == TRUE) { + BOOL ret ; + ret = theAccessBridge.IsJavaWindow(window); + return ret ; + + } + return FALSE; + } + + + /** + * Returns the virtual machine ID and AccessibleContext for a top-level window + */ + BOOL GetAccessibleContextFromHWND(HWND target, long *vmID, AccessibleContext *ac) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleContextFromHWND(target, vmID, ac); + } + return FALSE; + } + + /** + * Returns the HWND from the AccessibleContext of a top-level window. Returns 0 + * on error or if the AccessibleContext does not refer to a top-level window. + */ + HWND getHWNDFromAccessibleContext(long vmID, JOBJECT64 accesibleContext) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getHWNDFromAccessibleContext(vmID, accesibleContext); + } + return (HWND)0; + } + + /** + * returns whether two objects are the same + */ + BOOL IsSameObject(long vmID, JOBJECT64 obj1, JOBJECT64 obj2) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.IsSameObject(vmID, obj1, obj2); + } + return FALSE; + } + + /** + * Sets editable text contents. The AccessibleContext must implement AccessibleEditableText and + * be editable. The maximum text length is MAX_STRING_SIZE - 1. + * Returns whether successful + */ + BOOL setTextContents (const long vmID, const AccessibleContext accessibleContext, const wchar_t *text) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.setTextContents(vmID, accessibleContext, text); + } + return FALSE; + } + + /** + * Returns the Accessible Context with the specified role that is the + * ancestor of a given object. The role is one of the role strings + * defined in AccessBridgePackages.h + * If there is no ancestor object that has the specified role, + * returns (AccessibleContext)0. + */ + AccessibleContext getParentWithRole (const long vmID, const AccessibleContext accessibleContext, + const wchar_t *role) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getParentWithRole(vmID, accessibleContext, role); + } + return (AccessibleContext)0; + } + + /** + * Returns the Accessible Context with the specified role that is the + * ancestor of a given object. The role is one of the role strings + * defined in AccessBridgePackages.h. If an object with the specified + * role does not exist, returns the top level object for the Java Window. + * Returns (AccessibleContext)0 on error. + */ + AccessibleContext getParentWithRoleElseRoot (const long vmID, const AccessibleContext accessibleContext, + const wchar_t *role) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getParentWithRoleElseRoot(vmID, accessibleContext, role); + } + return (AccessibleContext)0; + } + + /** + * Returns the Accessible Context for the top level object in + * a Java Window. This is same Accessible Context that is obtained + * from GetAccessibleContextFromHWND for that window. Returns + * (AccessibleContext)0 on error. + */ + AccessibleContext getTopLevelObject (const long vmID, const AccessibleContext accessibleContext) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getTopLevelObject(vmID, accessibleContext); + } + return (AccessibleContext)0; + } + + /** + * Returns how deep in the object hierarchy a given object is. + * The top most object in the object hierarchy has an object depth of 0. + * Returns -1 on error. + */ + int getObjectDepth (const long vmID, const AccessibleContext accessibleContext) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getObjectDepth(vmID, accessibleContext); + } + return -1; + } + + /** + * Returns the Accessible Context of the current ActiveDescendent of an object. + * This method assumes the ActiveDescendent is the component that is currently + * selected in a container object. + * Returns (AccessibleContext)0 on error or if there is no selection. + */ + AccessibleContext getActiveDescendent (const long vmID, const AccessibleContext accessibleContext) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getActiveDescendent(vmID, accessibleContext); + } + return (AccessibleContext)0; + } + + + /** + * Accessible Context routines + */ + BOOL GetAccessibleContextAt(long vmID, AccessibleContext acParent, + jint x, jint y, AccessibleContext *ac) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleContextAt(vmID, acParent, x, y, ac); + } + return FALSE; + } + + BOOL GetAccessibleContextWithFocus(HWND window, long *vmID, AccessibleContext *ac) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleContextWithFocus(window, vmID, ac); + } + return FALSE; + } + + BOOL GetAccessibleContextInfo(long vmID, AccessibleContext ac, AccessibleContextInfo *info) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleContextInfo(vmID, ac, info); + } + return FALSE; + } + + AccessibleContext GetAccessibleChildFromContext(long vmID, AccessibleContext ac, jint index) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleChildFromContext(vmID, ac, index); + } + return (AccessibleContext) 0; + } + + AccessibleContext GetAccessibleParentFromContext(long vmID, AccessibleContext ac) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleParentFromContext(vmID, ac); + } + return (AccessibleContext) 0; + } + + /* begin AccessibleTable routines */ + + /* + * get information about an AccessibleTable + */ + BOOL getAccessibleTableInfo(long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableInfo(vmID, acParent, tableInfo); + } + return FALSE; + } + + /* + * get information about an AccessibleTable cell + */ + BOOL getAccessibleTableCellInfo(long vmID, AccessibleTable accessibleTable, + jint row, jint column, AccessibleTableCellInfo *tableCellInfo) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableCellInfo(vmID, accessibleTable, row, column, tableCellInfo); + } + return FALSE; + } + + /* + * get information about an AccessibleTable row header + */ + BOOL getAccessibleTableRowHeader(long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableRowHeader(vmID, acParent, tableInfo); + } + return FALSE; + } + + /* + * get information about an AccessibleTable column header + */ + BOOL getAccessibleTableColumnHeader(long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableColumnHeader(vmID, acParent, tableInfo); + } + return FALSE; + } + + /* + * return a description of an AccessibleTable row header + */ + AccessibleContext getAccessibleTableRowDescription(long vmID, AccessibleContext acParent, jint row) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableRowDescription(vmID, acParent, row); + } + return (AccessibleContext)0; + } + + /* + * return a description of an AccessibleTable column header + */ + AccessibleContext getAccessibleTableColumnDescription(long vmID, AccessibleContext acParent, jint column) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableColumnDescription(vmID, acParent, column); + } + return (AccessibleContext)0; + } + + /* + * return the number of rows selected in an AccessibleTable + */ + jint getAccessibleTableRowSelectionCount(long vmID, AccessibleTable table) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableRowSelectionCount(vmID, table); + } + return -1; + } + + /* + * return whether a row is selected in an AccessibleTable + */ + BOOL isAccessibleTableRowSelected(long vmID, AccessibleTable table, jint row) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.isAccessibleTableRowSelected(vmID, table, row); + } + return FALSE; + } + + /* + * get an array of selected rows in an AccessibleTable + */ + BOOL getAccessibleTableRowSelections(long vmID, AccessibleTable table, jint count, jint *selections) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableRowSelections(vmID, table, count, selections); + } + return FALSE; + } + + /* + * return the number of columns selected in an AccessibleTable + */ + jint getAccessibleTableColumnSelectionCount(long vmID, AccessibleTable table) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableColumnSelectionCount(vmID, table); + } + return -1; + } + + /* + * return whether a column is selected in an AccessibleTable + */ + BOOL isAccessibleTableColumnSelected(long vmID, AccessibleTable table, jint column) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.isAccessibleTableColumnSelected(vmID, table, column); + } + return FALSE; + } + + /* + * get an array of columns selected in an AccessibleTable + */ + BOOL getAccessibleTableColumnSelections(long vmID, AccessibleTable table, jint count, jint *selections) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableColumnSelections(vmID, table, count, selections); + } + return FALSE; + } + + /* + * return the row number for a cell at a given index + */ + jint + getAccessibleTableRow(long vmID, AccessibleTable table, jint index) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableRow(vmID, table, index); + } + return -1; + } + + /* + * return the column number for a cell at a given index + */ + jint + getAccessibleTableColumn(long vmID, AccessibleTable table, jint index) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableColumn(vmID, table, index); + } + return -1; + } + + /* + * return the index of a cell at a given row and column + */ + jint + getAccessibleTableIndex(long vmID, AccessibleTable table, jint row, jint column) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleTableIndex(vmID, table, row, column); + } + return -1; + } + + /* end AccessibleTable routines */ + + + /** + * Accessible Text routines + */ + BOOL GetAccessibleTextInfo(long vmID, AccessibleText at, AccessibleTextInfo *textInfo, jint x, jint y) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextInfo(vmID, at, textInfo, x, y); + } + return FALSE; + } + + BOOL GetAccessibleTextItems(long vmID, AccessibleText at, AccessibleTextItemsInfo *textItems, jint index) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextItems(vmID, at, textItems, index); + } + return FALSE; + } + + BOOL GetAccessibleTextSelectionInfo(long vmID, AccessibleText at, AccessibleTextSelectionInfo *textSelection) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextSelectionInfo(vmID, at, textSelection); + } + return FALSE; + } + + BOOL GetAccessibleTextAttributes(long vmID, AccessibleText at, jint index, AccessibleTextAttributesInfo *attributes) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextAttributes(vmID, at, index, attributes); + } + return FALSE; + } + + BOOL GetAccessibleTextRect(long vmID, AccessibleText at, AccessibleTextRectInfo *rectInfo, jint index) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextRect(vmID, at, rectInfo, index); + } + return FALSE; + } + + BOOL GetAccessibleTextLineBounds(long vmID, AccessibleText at, jint index, jint *startIndex, jint *endIndex) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextLineBounds(vmID, at, index, startIndex, endIndex); + } + return FALSE; + } + + BOOL GetAccessibleTextRange(long vmID, AccessibleText at, jint start, jint end, wchar_t *text, short len) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleTextRange(vmID, at, start, end, text, len); + } + return FALSE; + } + + /** + * AccessibleRelationSet routines + */ + BOOL getAccessibleRelationSet(long vmID, AccessibleContext accessibleContext, + AccessibleRelationSetInfo *relationSetInfo) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleRelationSet(vmID, accessibleContext, relationSetInfo); + } + return FALSE; + } + + /** + * AccessibleHypertext routines + */ + + // Gets AccessibleHypertext for an AccessibleContext + BOOL getAccessibleHypertext(long vmID, AccessibleContext accessibleContext, + AccessibleHypertextInfo *hypertextInfo) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleHypertext(vmID, accessibleContext, hypertextInfo); + } + return FALSE; + } + + // Activates an AccessibleHyperlink for an AccessibleContext + BOOL activateAccessibleHyperlink(long vmID, AccessibleContext accessibleContext, + AccessibleHyperlink accessibleHyperlink) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.activateAccessibleHyperlink(vmID, accessibleContext, accessibleHyperlink); + } + return FALSE; + } + + /* + * Returns the number of hyperlinks in a component + * Maps to AccessibleHypertext.getLinkCount. + * Returns -1 on error. + */ + jint getAccessibleHyperlinkCount(const long vmID, + const AccessibleContext accessibleContext) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleHyperlinkCount(vmID, accessibleContext); + } + return -1; + } + + /* + * This method is used to iterate through the hyperlinks in a component. It + * returns hypertext information for a component starting at hyperlink index + * nStartIndex. No more than MAX_HYPERLINKS AccessibleHypertextInfo objects will + * be returned for each call to this method. + * returns FALSE on error. + */ + BOOL getAccessibleHypertextExt(const long vmID, + const AccessibleContext accessibleContext, + const jint nStartIndex, + /* OUT */ AccessibleHypertextInfo *hypertextInfo) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleHypertextExt(vmID, + accessibleContext, + nStartIndex, + hypertextInfo); + } + return FALSE; + } + + /* + * Returns the index into an array of hyperlinks that is associated with + * a character index in document; + * Maps to AccessibleHypertext.getLinkIndex. + * Returns -1 on error. + */ + jint getAccessibleHypertextLinkIndex(const long vmID, + const AccessibleHypertext hypertext, + const jint nIndex) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleHypertextLinkIndex(vmID, + hypertext, + nIndex); + } + return -1; + } + + /* + * Returns the nth hyperlink in a document. + * Maps to AccessibleHypertext.getLink. + * Returns -1 on error + */ + BOOL getAccessibleHyperlink(const long vmID, + const AccessibleHypertext hypertext, + const jint nIndex, + /* OUT */ AccessibleHyperlinkInfo *hyperlinkInfo) { + + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleHyperlink(vmID, + hypertext, + nIndex, + hyperlinkInfo); + } + return FALSE; + } + + + /* Accessible KeyBindings, Icons and Actions */ + BOOL getAccessibleKeyBindings(long vmID, AccessibleContext accessibleContext, + AccessibleKeyBindings *keyBindings) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleKeyBindings(vmID, accessibleContext, keyBindings); + } + return FALSE; + } + + BOOL getAccessibleIcons(long vmID, AccessibleContext accessibleContext, + AccessibleIcons *icons) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleIcons(vmID, accessibleContext, icons); + } + return FALSE; + } + + BOOL getAccessibleActions(long vmID, AccessibleContext accessibleContext, + AccessibleActions *actions) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getAccessibleActions(vmID, accessibleContext, actions); + } + return FALSE; + } + + BOOL doAccessibleActions(long vmID, AccessibleContext accessibleContext, + AccessibleActionsToDo *actionsToDo, jint *failure) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.doAccessibleActions(vmID, accessibleContext, actionsToDo, failure); + } + return FALSE; + } + + /** + * Accessible Value routines + */ + BOOL GetCurrentAccessibleValueFromContext(long vmID, AccessibleValue av, wchar_t *value, short len) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetCurrentAccessibleValueFromContext(vmID, av, value, len); + } + return FALSE; + } + + BOOL GetMaximumAccessibleValueFromContext(long vmID, AccessibleValue av, wchar_t *value, short len) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetMaximumAccessibleValueFromContext(vmID, av, value, len); + } + return FALSE; + } + + BOOL GetMinimumAccessibleValueFromContext(long vmID, AccessibleValue av, wchar_t *value, short len) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetMinimumAccessibleValueFromContext(vmID, av, value, len); + } + return FALSE; + } + + + /** + * Accessible Selection routines + */ + void addAccessibleSelectionFromContext(long vmID, AccessibleSelection as, int i) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.AddAccessibleSelectionFromContext(vmID, as, i); + } + } + + void clearAccessibleSelectionFromContext(long vmID, AccessibleSelection as) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.ClearAccessibleSelectionFromContext(vmID, as); + } + } + + JOBJECT64 GetAccessibleSelectionFromContext(long vmID, AccessibleSelection as, int i) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleSelectionFromContext(vmID, as, i); + } + return (JOBJECT64) 0; + } + + int GetAccessibleSelectionCountFromContext(long vmID, AccessibleSelection as) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.GetAccessibleSelectionCountFromContext(vmID, as); + } + return -1; + } + + BOOL IsAccessibleChildSelectedFromContext(long vmID, AccessibleSelection as, int i) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.IsAccessibleChildSelectedFromContext(vmID, as, i); + } + return FALSE; + } + + void RemoveAccessibleSelectionFromContext(long vmID, AccessibleSelection as, int i) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.RemoveAccessibleSelectionFromContext(vmID, as, i); + } + } + + void SelectAllAccessibleSelectionFromContext(long vmID, AccessibleSelection as) { + if (theAccessBridgeInitializedFlag == TRUE) { + theAccessBridge.SelectAllAccessibleSelectionFromContext(vmID, as); + } + } + + /** + * Additional methods for Teton + */ + + /** + * Gets the AccessibleName for a component based upon the JAWS algorithm. Returns + * whether successful. + * + * Bug ID 4916682 - Implement JAWS AccessibleName policy + */ + BOOL getVirtualAccessibleName(const long vmID, const AccessibleContext accessibleContext, + wchar_t *name, int len) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getVirtualAccessibleName(vmID, accessibleContext, name, len); + } + return FALSE; + } + + /** + * Request focus for a component. Returns whether successful; + * + * Bug ID 4944757 - requestFocus method needed + */ + BOOL requestFocus(const long vmID, const AccessibleContext accessibleContext) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.requestFocus(vmID, accessibleContext); + } + return FALSE; + } + + /** + * Selects text between two indices. Selection includes the text at the start index + * and the text at the end index. Returns whether successful; + * + * Bug ID 4944758 - selectTextRange method needed + */ + BOOL selectTextRange(const long vmID, const AccessibleContext accessibleContext, + const int startIndex, const int endIndex) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.selectTextRange(vmID, accessibleContext, startIndex, endIndex); + } + return FALSE; + } + + /** + * Get text attributes between two indices. The attribute list includes the text at the + * start index and the text at the end index. Returns whether successful; + * + * Bug ID 4944761 - getTextAttributes between two indices method needed + */ + BOOL getTextAttributesInRange(const long vmID, const AccessibleContext accessibleContext, + const int startIndex, const int endIndex, + AccessibleTextAttributesInfo *attributes, short *len) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getTextAttributesInRange(vmID, accessibleContext, startIndex, + endIndex, attributes, len); + } + return FALSE; + } + + /** + * Returns the number of visible children of a component. Returns -1 on error. + * + * Bug ID 4944762- getVisibleChildren for list-like components needed + */ + int getVisibleChildrenCount(const long vmID, const AccessibleContext accessibleContext) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getVisibleChildrenCount(vmID, accessibleContext); + } + return FALSE; + } + + /** + * Gets the visible children of an AccessibleContext. Returns whether successful; + * + * Bug ID 4944762- getVisibleChildren for list-like components needed + */ + BOOL getVisibleChildren(const long vmID, const AccessibleContext accessibleContext, + const int startIndex, VisibleChildrenInfo *visibleChildrenInfo) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getVisibleChildren(vmID, accessibleContext, startIndex, + visibleChildrenInfo); + } + return FALSE; + } + + /** + * Set the caret to a text position. Returns whether successful; + * + * Bug ID 4944770 - setCaretPosition method needed + */ + BOOL setCaretPosition(const long vmID, const AccessibleContext accessibleContext, + const int position) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.setCaretPosition(vmID, accessibleContext, position); + } + return FALSE; + } + + /** + * Gets the text caret location + */ + BOOL getCaretLocation(long vmID, AccessibleContext ac, AccessibleTextRectInfo *rectInfo, jint index) { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getCaretLocation(vmID, ac, rectInfo, index); + } + return FALSE; + } + + /** + * Gets the number of events waiting to fire + */ + int getEventsWaiting() { + if (theAccessBridgeInitializedFlag == TRUE) { + return theAccessBridge.getEventsWaiting(); + } + return FALSE; + } + +#ifdef __cplusplus +} +#endif diff --git a/arthas-vmtool/src/main/native/head/windows/AccessBridgeCalls.h b/arthas-vmtool/src/main/native/head/windows/AccessBridgeCalls.h new file mode 100755 index 000000000..ad0074009 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/windows/AccessBridgeCalls.h @@ -0,0 +1,706 @@ +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * Wrapper functions around calls to the AccessBridge DLL + */ + +#include +#include +#include "AccessBridgeCallbacks.h" +#include "AccessBridgePackages.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define null NULL + + typedef JOBJECT64 AccessibleContext; + typedef JOBJECT64 AccessibleText; + typedef JOBJECT64 AccessibleValue; + typedef JOBJECT64 AccessibleSelection; + typedef JOBJECT64 Java_Object; + typedef JOBJECT64 PropertyChangeEvent; + typedef JOBJECT64 FocusEvent; + typedef JOBJECT64 CaretEvent; + typedef JOBJECT64 MouseEvent; + typedef JOBJECT64 MenuEvent; + typedef JOBJECT64 AccessibleTable; + typedef JOBJECT64 AccessibleHyperlink; + typedef JOBJECT64 AccessibleHypertext; + + + typedef void (*Windows_runFP) (); + + typedef void (*SetPropertyChangeFP) (AccessBridge_PropertyChangeFP fp); + + typedef void (*SetJavaShutdownFP) (AccessBridge_JavaShutdownFP fp); + typedef void (*SetFocusGainedFP) (AccessBridge_FocusGainedFP fp); + typedef void (*SetFocusLostFP) (AccessBridge_FocusLostFP fp); + + typedef void (*SetCaretUpdateFP) (AccessBridge_CaretUpdateFP fp); + + typedef void (*SetMouseClickedFP) (AccessBridge_MouseClickedFP fp); + typedef void (*SetMouseEnteredFP) (AccessBridge_MouseEnteredFP fp); + typedef void (*SetMouseExitedFP) (AccessBridge_MouseExitedFP fp); + typedef void (*SetMousePressedFP) (AccessBridge_MousePressedFP fp); + typedef void (*SetMouseReleasedFP) (AccessBridge_MouseReleasedFP fp); + + typedef void (*SetMenuCanceledFP) (AccessBridge_MenuCanceledFP fp); + typedef void (*SetMenuDeselectedFP) (AccessBridge_MenuDeselectedFP fp); + typedef void (*SetMenuSelectedFP) (AccessBridge_MenuSelectedFP fp); + typedef void (*SetPopupMenuCanceledFP) (AccessBridge_PopupMenuCanceledFP fp); + typedef void (*SetPopupMenuWillBecomeInvisibleFP) (AccessBridge_PopupMenuWillBecomeInvisibleFP fp); + typedef void (*SetPopupMenuWillBecomeVisibleFP) (AccessBridge_PopupMenuWillBecomeVisibleFP fp); + + typedef void (*SetPropertyNameChangeFP) (AccessBridge_PropertyNameChangeFP fp); + typedef void (*SetPropertyDescriptionChangeFP) (AccessBridge_PropertyDescriptionChangeFP fp); + typedef void (*SetPropertyStateChangeFP) (AccessBridge_PropertyStateChangeFP fp); + typedef void (*SetPropertyValueChangeFP) (AccessBridge_PropertyValueChangeFP fp); + typedef void (*SetPropertySelectionChangeFP) (AccessBridge_PropertySelectionChangeFP fp); + typedef void (*SetPropertyTextChangeFP) (AccessBridge_PropertyTextChangeFP fp); + typedef void (*SetPropertyCaretChangeFP) (AccessBridge_PropertyCaretChangeFP fp); + typedef void (*SetPropertyVisibleDataChangeFP) (AccessBridge_PropertyVisibleDataChangeFP fp); + typedef void (*SetPropertyChildChangeFP) (AccessBridge_PropertyChildChangeFP fp); + typedef void (*SetPropertyActiveDescendentChangeFP) (AccessBridge_PropertyActiveDescendentChangeFP fp); + + typedef void (*SetPropertyTableModelChangeFP) (AccessBridge_PropertyTableModelChangeFP fp); + + typedef void (*ReleaseJavaObjectFP) (long vmID, Java_Object object); + + typedef BOOL (*GetVersionInfoFP) (long vmID, AccessBridgeVersionInfo *info); + + typedef BOOL (*IsJavaWindowFP) (HWND window); + typedef BOOL (*IsSameObjectFP) (long vmID, JOBJECT64 obj1, JOBJECT64 obj2); + typedef BOOL (*GetAccessibleContextFromHWNDFP) (HWND window, long *vmID, AccessibleContext *ac); + typedef HWND (*getHWNDFromAccessibleContextFP) (long vmID, AccessibleContext ac); + + typedef BOOL (*GetAccessibleContextAtFP) (long vmID, AccessibleContext acParent, + jint x, jint y, AccessibleContext *ac); + typedef BOOL (*GetAccessibleContextWithFocusFP) (HWND window, long *vmID, AccessibleContext *ac); + typedef BOOL (*GetAccessibleContextInfoFP) (long vmID, AccessibleContext ac, AccessibleContextInfo *info); + typedef AccessibleContext (*GetAccessibleChildFromContextFP) (long vmID, AccessibleContext ac, jint i); + typedef AccessibleContext (*GetAccessibleParentFromContextFP) (long vmID, AccessibleContext ac); + + /* begin AccessibleTable */ + typedef BOOL (*getAccessibleTableInfoFP) (long vmID, AccessibleContext ac, AccessibleTableInfo *tableInfo); + typedef BOOL (*getAccessibleTableCellInfoFP) (long vmID, AccessibleTable accessibleTable, + jint row, jint column, AccessibleTableCellInfo *tableCellInfo); + + typedef BOOL (*getAccessibleTableRowHeaderFP) (long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo); + typedef BOOL (*getAccessibleTableColumnHeaderFP) (long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo); + + typedef AccessibleContext (*getAccessibleTableRowDescriptionFP) (long vmID, AccessibleContext acParent, jint row); + typedef AccessibleContext (*getAccessibleTableColumnDescriptionFP) (long vmID, AccessibleContext acParent, jint column); + + typedef jint (*getAccessibleTableRowSelectionCountFP) (long vmID, AccessibleTable table); + typedef BOOL (*isAccessibleTableRowSelectedFP) (long vmID, AccessibleTable table, jint row); + typedef BOOL (*getAccessibleTableRowSelectionsFP) (long vmID, AccessibleTable table, jint count, + jint *selections); + + typedef jint (*getAccessibleTableColumnSelectionCountFP) (long vmID, AccessibleTable table); + typedef BOOL (*isAccessibleTableColumnSelectedFP) (long vmID, AccessibleTable table, jint column); + typedef BOOL (*getAccessibleTableColumnSelectionsFP) (long vmID, AccessibleTable table, jint count, + jint *selections); + + typedef jint (*getAccessibleTableRowFP) (long vmID, AccessibleTable table, jint index); + typedef jint (*getAccessibleTableColumnFP) (long vmID, AccessibleTable table, jint index); + typedef jint (*getAccessibleTableIndexFP) (long vmID, AccessibleTable table, jint row, jint column); + /* end AccessibleTable */ + + /* AccessibleRelationSet */ + typedef BOOL (*getAccessibleRelationSetFP) (long vmID, AccessibleContext accessibleContext, + AccessibleRelationSetInfo *relationSetInfo); + + /* AccessibleHypertext */ + typedef BOOL (*getAccessibleHypertextFP)(long vmID, AccessibleContext accessibleContext, + AccessibleHypertextInfo *hypertextInfo); + + typedef BOOL (*activateAccessibleHyperlinkFP)(long vmID, AccessibleContext accessibleContext, + AccessibleHyperlink accessibleHyperlink); + + typedef jint (*getAccessibleHyperlinkCountFP)(const long vmID, + const AccessibleContext accessibleContext); + + typedef BOOL (*getAccessibleHypertextExtFP) (const long vmID, + const AccessibleContext accessibleContext, + const jint nStartIndex, + AccessibleHypertextInfo *hypertextInfo); + + typedef jint (*getAccessibleHypertextLinkIndexFP)(const long vmID, + const AccessibleHypertext hypertext, + const jint nIndex); + + typedef BOOL (*getAccessibleHyperlinkFP)(const long vmID, + const AccessibleHypertext hypertext, + const jint nIndex, + AccessibleHyperlinkInfo *hyperlinkInfo); + + + /* Accessible KeyBindings, Icons and Actions */ + typedef BOOL (*getAccessibleKeyBindingsFP)(long vmID, AccessibleContext accessibleContext, + AccessibleKeyBindings *keyBindings); + + typedef BOOL (*getAccessibleIconsFP)(long vmID, AccessibleContext accessibleContext, + AccessibleIcons *icons); + + typedef BOOL (*getAccessibleActionsFP)(long vmID, AccessibleContext accessibleContext, + AccessibleActions *actions); + + typedef BOOL (*doAccessibleActionsFP)(long vmID, AccessibleContext accessibleContext, + AccessibleActionsToDo *actionsToDo, jint *failure); + + + /* AccessibleText */ + + typedef BOOL (*GetAccessibleTextInfoFP) (long vmID, AccessibleText at, AccessibleTextInfo *textInfo, jint x, jint y); + typedef BOOL (*GetAccessibleTextItemsFP) (long vmID, AccessibleText at, AccessibleTextItemsInfo *textItems, jint index); + typedef BOOL (*GetAccessibleTextSelectionInfoFP) (long vmID, AccessibleText at, AccessibleTextSelectionInfo *textSelection); + typedef BOOL (*GetAccessibleTextAttributesFP) (long vmID, AccessibleText at, jint index, AccessibleTextAttributesInfo *attributes); + typedef BOOL (*GetAccessibleTextRectFP) (long vmID, AccessibleText at, AccessibleTextRectInfo *rectInfo, jint index); + typedef BOOL (*GetAccessibleTextLineBoundsFP) (long vmID, AccessibleText at, jint index, jint *startIndex, jint *endIndex); + typedef BOOL (*GetAccessibleTextRangeFP) (long vmID, AccessibleText at, jint start, jint end, wchar_t *text, short len); + + typedef BOOL (*GetCurrentAccessibleValueFromContextFP) (long vmID, AccessibleValue av, wchar_t *value, short len); + typedef BOOL (*GetMaximumAccessibleValueFromContextFP) (long vmID, AccessibleValue av, wchar_t *value, short len); + typedef BOOL (*GetMinimumAccessibleValueFromContextFP) (long vmID, AccessibleValue av, wchar_t *value, short len); + + typedef void (*AddAccessibleSelectionFromContextFP) (long vmID, AccessibleSelection as, int i); + typedef void (*ClearAccessibleSelectionFromContextFP) (long vmID, AccessibleSelection as); + typedef JOBJECT64 (*GetAccessibleSelectionFromContextFP) (long vmID, AccessibleSelection as, int i); + typedef int (*GetAccessibleSelectionCountFromContextFP) (long vmID, AccessibleSelection as); + typedef BOOL (*IsAccessibleChildSelectedFromContextFP) (long vmID, AccessibleSelection as, int i); + typedef void (*RemoveAccessibleSelectionFromContextFP) (long vmID, AccessibleSelection as, int i); + typedef void (*SelectAllAccessibleSelectionFromContextFP) (long vmID, AccessibleSelection as); + + /* Utility methods */ + + typedef BOOL (*setTextContentsFP) (const long vmID, const AccessibleContext ac, const wchar_t *text); + typedef AccessibleContext (*getParentWithRoleFP) (const long vmID, const AccessibleContext ac, const wchar_t *role); + typedef AccessibleContext (*getParentWithRoleElseRootFP) (const long vmID, const AccessibleContext ac, const wchar_t *role); + typedef AccessibleContext (*getTopLevelObjectFP) (const long vmID, const AccessibleContext ac); + typedef int (*getObjectDepthFP) (const long vmID, const AccessibleContext ac); + typedef AccessibleContext (*getActiveDescendentFP) (const long vmID, const AccessibleContext ac); + + + typedef BOOL (*getVirtualAccessibleNameFP) (const long vmID, const AccessibleContext accessibleContext, + wchar_t *name, int len); + + typedef BOOL (*requestFocusFP) (const long vmID, const AccessibleContext accessibleContext); + + typedef BOOL (*selectTextRangeFP) (const long vmID, const AccessibleContext accessibleContext, + const int startIndex, const int endIndex); + + typedef BOOL (*getTextAttributesInRangeFP) (const long vmID, const AccessibleContext accessibleContext, + const int startIndex, const int endIndex, + AccessibleTextAttributesInfo *attributes, short *len); + + typedef int (*getVisibleChildrenCountFP) (const long vmID, const AccessibleContext accessibleContext); + + typedef BOOL (*getVisibleChildrenFP) (const long vmID, const AccessibleContext accessibleContext, + const int startIndex, VisibleChildrenInfo *children); + + typedef BOOL (*setCaretPositionFP) (const long vmID, const AccessibleContext accessibleContext, const int position); + + typedef BOOL (*getCaretLocationFP) (long vmID, AccessibleContext ac, AccessibleTextRectInfo *rectInfo, jint index); + + typedef int (*getEventsWaitingFP) (); + + typedef struct AccessBridgeFPsTag { + Windows_runFP Windows_run; + + SetPropertyChangeFP SetPropertyChange; + + SetJavaShutdownFP SetJavaShutdown; + SetFocusGainedFP SetFocusGained; + SetFocusLostFP SetFocusLost; + + SetCaretUpdateFP SetCaretUpdate; + + SetMouseClickedFP SetMouseClicked; + SetMouseEnteredFP SetMouseEntered; + SetMouseExitedFP SetMouseExited; + SetMousePressedFP SetMousePressed; + SetMouseReleasedFP SetMouseReleased; + + SetMenuCanceledFP SetMenuCanceled; + SetMenuDeselectedFP SetMenuDeselected; + SetMenuSelectedFP SetMenuSelected; + SetPopupMenuCanceledFP SetPopupMenuCanceled; + SetPopupMenuWillBecomeInvisibleFP SetPopupMenuWillBecomeInvisible; + SetPopupMenuWillBecomeVisibleFP SetPopupMenuWillBecomeVisible; + + SetPropertyNameChangeFP SetPropertyNameChange; + SetPropertyDescriptionChangeFP SetPropertyDescriptionChange; + SetPropertyStateChangeFP SetPropertyStateChange; + SetPropertyValueChangeFP SetPropertyValueChange; + SetPropertySelectionChangeFP SetPropertySelectionChange; + SetPropertyTextChangeFP SetPropertyTextChange; + SetPropertyCaretChangeFP SetPropertyCaretChange; + SetPropertyVisibleDataChangeFP SetPropertyVisibleDataChange; + SetPropertyChildChangeFP SetPropertyChildChange; + SetPropertyActiveDescendentChangeFP SetPropertyActiveDescendentChange; + + SetPropertyTableModelChangeFP SetPropertyTableModelChange; + + ReleaseJavaObjectFP ReleaseJavaObject; + GetVersionInfoFP GetVersionInfo; + + IsJavaWindowFP IsJavaWindow; + IsSameObjectFP IsSameObject; + GetAccessibleContextFromHWNDFP GetAccessibleContextFromHWND; + getHWNDFromAccessibleContextFP getHWNDFromAccessibleContext; + + GetAccessibleContextAtFP GetAccessibleContextAt; + GetAccessibleContextWithFocusFP GetAccessibleContextWithFocus; + GetAccessibleContextInfoFP GetAccessibleContextInfo; + GetAccessibleChildFromContextFP GetAccessibleChildFromContext; + GetAccessibleParentFromContextFP GetAccessibleParentFromContext; + + getAccessibleTableInfoFP getAccessibleTableInfo; + getAccessibleTableCellInfoFP getAccessibleTableCellInfo; + + getAccessibleTableRowHeaderFP getAccessibleTableRowHeader; + getAccessibleTableColumnHeaderFP getAccessibleTableColumnHeader; + + getAccessibleTableRowDescriptionFP getAccessibleTableRowDescription; + getAccessibleTableColumnDescriptionFP getAccessibleTableColumnDescription; + + getAccessibleTableRowSelectionCountFP getAccessibleTableRowSelectionCount; + isAccessibleTableRowSelectedFP isAccessibleTableRowSelected; + getAccessibleTableRowSelectionsFP getAccessibleTableRowSelections; + + getAccessibleTableColumnSelectionCountFP getAccessibleTableColumnSelectionCount; + isAccessibleTableColumnSelectedFP isAccessibleTableColumnSelected; + getAccessibleTableColumnSelectionsFP getAccessibleTableColumnSelections; + + getAccessibleTableRowFP getAccessibleTableRow; + getAccessibleTableColumnFP getAccessibleTableColumn; + getAccessibleTableIndexFP getAccessibleTableIndex; + + getAccessibleRelationSetFP getAccessibleRelationSet; + + getAccessibleHypertextFP getAccessibleHypertext; + activateAccessibleHyperlinkFP activateAccessibleHyperlink; + getAccessibleHyperlinkCountFP getAccessibleHyperlinkCount; + getAccessibleHypertextExtFP getAccessibleHypertextExt; + getAccessibleHypertextLinkIndexFP getAccessibleHypertextLinkIndex; + getAccessibleHyperlinkFP getAccessibleHyperlink; + + getAccessibleKeyBindingsFP getAccessibleKeyBindings; + getAccessibleIconsFP getAccessibleIcons; + getAccessibleActionsFP getAccessibleActions; + doAccessibleActionsFP doAccessibleActions; + + GetAccessibleTextInfoFP GetAccessibleTextInfo; + GetAccessibleTextItemsFP GetAccessibleTextItems; + GetAccessibleTextSelectionInfoFP GetAccessibleTextSelectionInfo; + GetAccessibleTextAttributesFP GetAccessibleTextAttributes; + GetAccessibleTextRectFP GetAccessibleTextRect; + GetAccessibleTextLineBoundsFP GetAccessibleTextLineBounds; + GetAccessibleTextRangeFP GetAccessibleTextRange; + + GetCurrentAccessibleValueFromContextFP GetCurrentAccessibleValueFromContext; + GetMaximumAccessibleValueFromContextFP GetMaximumAccessibleValueFromContext; + GetMinimumAccessibleValueFromContextFP GetMinimumAccessibleValueFromContext; + + AddAccessibleSelectionFromContextFP AddAccessibleSelectionFromContext; + ClearAccessibleSelectionFromContextFP ClearAccessibleSelectionFromContext; + GetAccessibleSelectionFromContextFP GetAccessibleSelectionFromContext; + GetAccessibleSelectionCountFromContextFP GetAccessibleSelectionCountFromContext; + IsAccessibleChildSelectedFromContextFP IsAccessibleChildSelectedFromContext; + RemoveAccessibleSelectionFromContextFP RemoveAccessibleSelectionFromContext; + SelectAllAccessibleSelectionFromContextFP SelectAllAccessibleSelectionFromContext; + + setTextContentsFP setTextContents; + getParentWithRoleFP getParentWithRole; + getTopLevelObjectFP getTopLevelObject; + getParentWithRoleElseRootFP getParentWithRoleElseRoot; + getObjectDepthFP getObjectDepth; + getActiveDescendentFP getActiveDescendent; + + getVirtualAccessibleNameFP getVirtualAccessibleName; + requestFocusFP requestFocus; + selectTextRangeFP selectTextRange; + getTextAttributesInRangeFP getTextAttributesInRange; + getVisibleChildrenCountFP getVisibleChildrenCount; + getVisibleChildrenFP getVisibleChildren; + setCaretPositionFP setCaretPosition; + getCaretLocationFP getCaretLocation; + + getEventsWaitingFP getEventsWaiting; + + } AccessBridgeFPs; + + + /** + * Initialize the world + */ + BOOL initializeAccessBridge(); + BOOL shutdownAccessBridge(); + + /** + * Window routines + */ + BOOL IsJavaWindow(HWND window); + + // Returns the virtual machine ID and AccessibleContext for a top-level window + BOOL GetAccessibleContextFromHWND(HWND target, long *vmID, AccessibleContext *ac); + + // Returns the HWND from the AccessibleContext of a top-level window + HWND getHWNDFromAccessibleContext(long vmID, AccessibleContext ac); + + + /** + * Event handling routines + */ + void SetJavaShutdown(AccessBridge_JavaShutdownFP fp); + void SetFocusGained(AccessBridge_FocusGainedFP fp); + void SetFocusLost(AccessBridge_FocusLostFP fp); + + void SetCaretUpdate(AccessBridge_CaretUpdateFP fp); + + void SetMouseClicked(AccessBridge_MouseClickedFP fp); + void SetMouseEntered(AccessBridge_MouseEnteredFP fp); + void SetMouseExited(AccessBridge_MouseExitedFP fp); + void SetMousePressed(AccessBridge_MousePressedFP fp); + void SetMouseReleased(AccessBridge_MouseReleasedFP fp); + + void SetMenuCanceled(AccessBridge_MenuCanceledFP fp); + void SetMenuDeselected(AccessBridge_MenuDeselectedFP fp); + void SetMenuSelected(AccessBridge_MenuSelectedFP fp); + void SetPopupMenuCanceled(AccessBridge_PopupMenuCanceledFP fp); + void SetPopupMenuWillBecomeInvisible(AccessBridge_PopupMenuWillBecomeInvisibleFP fp); + void SetPopupMenuWillBecomeVisible(AccessBridge_PopupMenuWillBecomeVisibleFP fp); + + void SetPropertyNameChange(AccessBridge_PropertyNameChangeFP fp); + void SetPropertyDescriptionChange(AccessBridge_PropertyDescriptionChangeFP fp); + void SetPropertyStateChange(AccessBridge_PropertyStateChangeFP fp); + void SetPropertyValueChange(AccessBridge_PropertyValueChangeFP fp); + void SetPropertySelectionChange(AccessBridge_PropertySelectionChangeFP fp); + void SetPropertyTextChange(AccessBridge_PropertyTextChangeFP fp); + void SetPropertyCaretChange(AccessBridge_PropertyCaretChangeFP fp); + void SetPropertyVisibleDataChange(AccessBridge_PropertyVisibleDataChangeFP fp); + void SetPropertyChildChange(AccessBridge_PropertyChildChangeFP fp); + void SetPropertyActiveDescendentChange(AccessBridge_PropertyActiveDescendentChangeFP fp); + + void SetPropertyTableModelChange(AccessBridge_PropertyTableModelChangeFP fp); + + + /** + * General routines + */ + void ReleaseJavaObject(long vmID, Java_Object object); + BOOL GetVersionInfo(long vmID, AccessBridgeVersionInfo *info); + HWND GetHWNDFromAccessibleContext(long vmID, JOBJECT64 accesibleContext); + + /** + * Accessible Context routines + */ + BOOL GetAccessibleContextAt(long vmID, AccessibleContext acParent, + jint x, jint y, AccessibleContext *ac); + BOOL GetAccessibleContextWithFocus(HWND window, long *vmID, AccessibleContext *ac); + BOOL GetAccessibleContextInfo(long vmID, AccessibleContext ac, AccessibleContextInfo *info); + AccessibleContext GetAccessibleChildFromContext(long vmID, AccessibleContext ac, jint index); + AccessibleContext GetAccessibleParentFromContext(long vmID, AccessibleContext ac); + + /** + * Accessible Text routines + */ + BOOL GetAccessibleTextInfo(long vmID, AccessibleText at, AccessibleTextInfo *textInfo, jint x, jint y); + BOOL GetAccessibleTextItems(long vmID, AccessibleText at, AccessibleTextItemsInfo *textItems, jint index); + BOOL GetAccessibleTextSelectionInfo(long vmID, AccessibleText at, AccessibleTextSelectionInfo *textSelection); + BOOL GetAccessibleTextAttributes(long vmID, AccessibleText at, jint index, AccessibleTextAttributesInfo *attributes); + BOOL GetAccessibleTextRect(long vmID, AccessibleText at, AccessibleTextRectInfo *rectInfo, jint index); + BOOL GetAccessibleTextLineBounds(long vmID, AccessibleText at, jint index, jint *startIndex, jint *endIndex); + BOOL GetAccessibleTextRange(long vmID, AccessibleText at, jint start, jint end, wchar_t *text, short len); + + /* begin AccessibleTable routines */ + BOOL getAccessibleTableInfo(long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo); + + BOOL getAccessibleTableCellInfo(long vmID, AccessibleTable accessibleTable, jint row, jint column, + AccessibleTableCellInfo *tableCellInfo); + + BOOL getAccessibleTableRowHeader(long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo); + BOOL getAccessibleTableColumnHeader(long vmID, AccessibleContext acParent, AccessibleTableInfo *tableInfo); + + AccessibleContext getAccessibleTableRowDescription(long vmID, AccessibleContext acParent, jint row); + AccessibleContext getAccessibleTableColumnDescription(long vmID, AccessibleContext acParent, jint column); + + jint getAccessibleTableRowSelectionCount(long vmID, AccessibleTable table); + BOOL isAccessibleTableRowSelected(long vmID, AccessibleTable table, jint row); + BOOL getAccessibleTableRowSelections(long vmID, AccessibleTable table, jint count, jint *selections); + + jint getAccessibleTableColumnSelectionCount(long vmID, AccessibleTable table); + BOOL isAccessibleTableColumnSelected(long vmID, AccessibleTable table, jint column); + BOOL getAccessibleTableColumnSelections(long vmID, AccessibleTable table, jint count, jint *selections); + + jint getAccessibleTableRow(long vmID, AccessibleTable table, jint index); + jint getAccessibleTableColumn(long vmID, AccessibleTable table, jint index); + jint getAccessibleTableIndex(long vmID, AccessibleTable table, jint row, jint column); + /* end AccessibleTable */ + + /* ----- AccessibleRelationSet routines */ + BOOL getAccessibleRelationSet(long vmID, AccessibleContext accessibleContext, + AccessibleRelationSetInfo *relationSetInfo); + + /* ----- AccessibleHypertext routines */ + + /* + * Returns hypertext information associated with a component. + */ + BOOL getAccessibleHypertext(long vmID, AccessibleContext accessibleContext, + AccessibleHypertextInfo *hypertextInfo); + + /* + * Requests that a hyperlink be activated. + */ + BOOL activateAccessibleHyperlink(long vmID, AccessibleContext accessibleContext, + AccessibleHyperlink accessibleHyperlink); + + /* + * Returns the number of hyperlinks in a component + * Maps to AccessibleHypertext.getLinkCount. + * Returns -1 on error. + */ + jint getAccessibleHyperlinkCount(const long vmID, + const AccessibleHypertext hypertext); + + /* + * This method is used to iterate through the hyperlinks in a component. It + * returns hypertext information for a component starting at hyperlink index + * nStartIndex. No more than MAX_HYPERLINKS AccessibleHypertextInfo objects will + * be returned for each call to this method. + * Returns FALSE on error. + */ + BOOL getAccessibleHypertextExt(const long vmID, + const AccessibleContext accessibleContext, + const jint nStartIndex, + /* OUT */ AccessibleHypertextInfo *hypertextInfo); + + /* + * Returns the index into an array of hyperlinks that is associated with + * a character index in document; maps to AccessibleHypertext.getLinkIndex + * Returns -1 on error. + */ + jint getAccessibleHypertextLinkIndex(const long vmID, + const AccessibleHypertext hypertext, + const jint nIndex); + + /* + * Returns the nth hyperlink in a document + * Maps to AccessibleHypertext.getLink. + * Returns FALSE on error + */ + BOOL getAccessibleHyperlink(const long vmID, + const AccessibleHypertext hypertext, + const jint nIndex, + /* OUT */ AccessibleHyperlinkInfo *hyperlinkInfo); + + /* Accessible KeyBindings, Icons and Actions */ + + /* + * Returns a list of key bindings associated with a component. + */ + BOOL getAccessibleKeyBindings(long vmID, AccessibleContext accessibleContext, + AccessibleKeyBindings *keyBindings); + + /* + * Returns a list of icons associate with a component. + */ + BOOL getAccessibleIcons(long vmID, AccessibleContext accessibleContext, + AccessibleIcons *icons); + + /* + * Returns a list of actions that a component can perform. + */ + BOOL getAccessibleActions(long vmID, AccessibleContext accessibleContext, + AccessibleActions *actions); + + /* + * Request that a list of AccessibleActions be performed by a component. + * Returns TRUE if all actions are performed. Returns FALSE + * when the first requested action fails in which case "failure" + * contains the index of the action that failed. + */ + BOOL doAccessibleActions(long vmID, AccessibleContext accessibleContext, + AccessibleActionsToDo *actionsToDo, jint *failure); + + + + /* Additional utility methods */ + + /* + * Returns whether two object references refer to the same object. + */ + BOOL IsSameObject(long vmID, JOBJECT64 obj1, JOBJECT64 obj2); + + /** + * Sets editable text contents. The AccessibleContext must implement AccessibleEditableText and + * be editable. The maximum text length that can be set is MAX_STRING_SIZE - 1. + * Returns whether successful + */ + BOOL setTextContents (const long vmID, const AccessibleContext accessibleContext, const wchar_t *text); + + /** + * Returns the Accessible Context with the specified role that is the + * ancestor of a given object. The role is one of the role strings + * defined in AccessBridgePackages.h + * If there is no ancestor object that has the specified role, + * returns (AccessibleContext)0. + */ + AccessibleContext getParentWithRole (const long vmID, const AccessibleContext accessibleContext, + const wchar_t *role); + + /** + * Returns the Accessible Context with the specified role that is the + * ancestor of a given object. The role is one of the role strings + * defined in AccessBridgePackages.h. If an object with the specified + * role does not exist, returns the top level object for the Java Window. + * Returns (AccessibleContext)0 on error. + */ + AccessibleContext getParentWithRoleElseRoot (const long vmID, const AccessibleContext accessibleContext, + const wchar_t *role); + + /** + * Returns the Accessible Context for the top level object in + * a Java Window. This is same Accessible Context that is obtained + * from GetAccessibleContextFromHWND for that window. Returns + * (AccessibleContext)0 on error. + */ + AccessibleContext getTopLevelObject (const long vmID, const AccessibleContext accessibleContext); + + /** + * Returns how deep in the object hierarchy a given object is. + * The top most object in the object hierarchy has an object depth of 0. + * Returns -1 on error. + */ + int getObjectDepth (const long vmID, const AccessibleContext accessibleContext); + + /** + * Returns the Accessible Context of the current ActiveDescendent of an object. + * This method assumes the ActiveDescendent is the component that is currently + * selected in a container object. + * Returns (AccessibleContext)0 on error or if there is no selection. + */ + AccessibleContext getActiveDescendent (const long vmID, const AccessibleContext accessibleContext); + + /** + /** + * Accessible Value routines + */ + BOOL GetCurrentAccessibleValueFromContext(long vmID, AccessibleValue av, wchar_t *value, short len); + BOOL GetMaximumAccessibleValueFromContext(long vmID, AccessibleValue av, wchar_t *value, short len); + BOOL GetMinimumAccessibleValueFromContext(long vmID, AccessibleValue av, wchar_t *value, short len); + + /** + * Accessible Selection routines + */ + void AddAccessibleSelectionFromContext(long vmID, AccessibleSelection as, int i); + void ClearAccessibleSelectionFromContext(long vmID, AccessibleSelection as); + JOBJECT64 GetAccessibleSelectionFromContext(long vmID, AccessibleSelection as, int i); + int GetAccessibleSelectionCountFromContext(long vmID, AccessibleSelection as); + BOOL IsAccessibleChildSelectedFromContext(long vmID, AccessibleSelection as, int i); + void RemoveAccessibleSelectionFromContext(long vmID, AccessibleSelection as, int i); + void SelectAllAccessibleSelectionFromContext(long vmID, AccessibleSelection as); + + /** + * Additional methods for Teton + */ + + /** + * Gets the AccessibleName for a component based upon the JAWS algorithm. Returns + * whether successful. + * + * Bug ID 4916682 - Implement JAWS AccessibleName policy + */ + BOOL getVirtualAccessibleName(const long vmID, const AccessibleContext accessibleContext, + wchar_t *name, int len); + + /** + * Request focus for a component. Returns whether successful. + * + * Bug ID 4944757 - requestFocus method needed + */ + BOOL requestFocus(const long vmID, const AccessibleContext accessibleContext); + + /** + * Selects text between two indices. Selection includes the text at the start index + * and the text at the end index. Returns whether successful. + * + * Bug ID 4944758 - selectTextRange method needed + */ + BOOL selectTextRange(const long vmID, const AccessibleContext accessibleContext, const int startIndex, + const int endIndex); + + /** + * Get text attributes between two indices. The attribute list includes the text at the + * start index and the text at the end index. Returns whether successful; + * + * Bug ID 4944761 - getTextAttributes between two indices method needed + */ + BOOL getTextAttributesInRange(const long vmID, const AccessibleContext accessibleContext, + const int startIndex, const int endIndex, + AccessibleTextAttributesInfo *attributes, short *len); + + /** + * Returns the number of visible children of a component. Returns -1 on error. + * + * Bug ID 4944762- getVisibleChildren for list-like components needed + */ + int getVisibleChildrenCount(const long vmID, const AccessibleContext accessibleContext); + + /** + * Gets the visible children of an AccessibleContext. Returns whether successful. + * + * Bug ID 4944762- getVisibleChildren for list-like components needed + */ + BOOL getVisibleChildren(const long vmID, const AccessibleContext accessibleContext, + const int startIndex, + VisibleChildrenInfo *visibleChildrenInfo); + + /** + * Set the caret to a text position. Returns whether successful. + * + * Bug ID 4944770 - setCaretPosition method needed + */ + BOOL setCaretPosition(const long vmID, const AccessibleContext accessibleContext, + const int position); + + /** + * Gets the text caret location + */ + BOOL getCaretLocation(long vmID, AccessibleContext ac, + AccessibleTextRectInfo *rectInfo, jint index); + + /** + * Gets the number of events waiting to fire + */ + int getEventsWaiting(); + +#ifdef __cplusplus +} +#endif diff --git a/arthas-vmtool/src/main/native/head/windows/AccessBridgePackages.h b/arthas-vmtool/src/main/native/head/windows/AccessBridgePackages.h new file mode 100755 index 000000000..478f7c636 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/windows/AccessBridgePackages.h @@ -0,0 +1,2215 @@ +/* + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +/* + * Header file for packages of paramaters passed between Java Accessibility + * and native Assistive Technologies + */ + +#ifndef __AccessBridgePackages_H__ +#define __AccessBridgePackages_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef ACCESSBRIDGE_ARCH_LEGACY +typedef jobject JOBJECT64; +typedef HWND ABHWND64; +#define ABHandleToLong +#define ABLongToHandle +#else +typedef jlong JOBJECT64; +typedef long ABHWND64; +#define ABHandleToLong HandleToLong +#define ABLongToHandle LongToHandle +#endif + +#define MAX_BUFFER_SIZE 10240 +#define MAX_STRING_SIZE 1024 +#define SHORT_STRING_SIZE 256 + + // object types + typedef JOBJECT64 AccessibleContext; + typedef JOBJECT64 AccessibleText; + typedef JOBJECT64 AccessibleValue; + typedef JOBJECT64 AccessibleSelection; + typedef JOBJECT64 Java_Object; + typedef JOBJECT64 PropertyChangeEvent; + typedef JOBJECT64 FocusEvent; + typedef JOBJECT64 CaretEvent; + typedef JOBJECT64 MouseEvent; + typedef JOBJECT64 MenuEvent; + typedef JOBJECT64 AccessibleTable; + typedef JOBJECT64 AccessibleHyperlink; + typedef JOBJECT64 AccessibleHypertext; + + /** + ****************************************************** + * Java event types + ****************************************************** + */ + +#define cPropertyChangeEvent (jlong) 1 // 1 +#define cFocusGainedEvent (jlong) 2 // 2 +#define cFocusLostEvent (jlong) 4 // 4 +#define cCaretUpdateEvent (jlong) 8 // 8 +#define cMouseClickedEvent (jlong) 16 // 10 +#define cMouseEnteredEvent (jlong) 32 // 20 +#define cMouseExitedEvent (jlong) 64 // 40 +#define cMousePressedEvent (jlong) 128 // 80 +#define cMouseReleasedEvent (jlong) 256 // 100 +#define cMenuCanceledEvent (jlong) 512 // 200 +#define cMenuDeselectedEvent (jlong) 1024 // 400 +#define cMenuSelectedEvent (jlong) 2048 // 800 +#define cPopupMenuCanceledEvent (jlong) 4096 // 1000 +#define cPopupMenuWillBecomeInvisibleEvent (jlong) 8192 // 2000 +#define cPopupMenuWillBecomeVisibleEvent (jlong) 16384 // 4000 +#define cJavaShutdownEvent (jlong) 32768 // 8000 + + /** + ****************************************************** + * Accessible Roles + * Defines all AccessibleRoles in Local.US + ****************************************************** + */ + + /** + * Object is used to alert the user about something. + */ +#define ACCESSIBLE_ALERT L"alert" + + /** + * The header for a column of data. + */ +#define ACCESSIBLE_COLUMN_HEADER L"column header" + + /** + * Object that can be drawn into and is used to trap + * events. + * see ACCESSIBLE_FRAME + * see ACCESSIBLE_GLASS_PANE + * see ACCESSIBLE_LAYERED_PANE + */ +#define ACCESSIBLE_CANVAS L"canvas" + + /** + * A list of choices the user can select from. Also optionally + * allows the user to enter a choice of their own. + */ +#define ACCESSIBLE_COMBO_BOX L"combo box" + + /** + * An iconified internal frame in a DESKTOP_PANE. + * see ACCESSIBLE_DESKTOP_PANE + * see ACCESSIBLE_INTERNAL_FRAME + */ +#define ACCESSIBLE_DESKTOP_ICON L"desktop icon" + + /** + * A frame-like object that is clipped by a desktop pane. The + * desktop pane, internal frame, and desktop icon objects are + * often used to create multiple document interfaces within an + * application. + * see ACCESSIBLE_DESKTOP_ICON + * see ACCESSIBLE_DESKTOP_PANE + * see ACCESSIBLE_FRAME + */ +#define ACCESSIBLE_INTERNAL_FRAME L"internal frame" + + /** + * A pane that supports internal frames and + * iconified versions of those internal frames. + * see ACCESSIBLE_DESKTOP_ICON + * see ACCESSIBLE_INTERNAL_FRAME + */ +#define ACCESSIBLE_DESKTOP_PANE L"desktop pane" + + /** + * A specialized pane whose primary use is inside a DIALOG + * see ACCESSIBLE_DIALOG + */ +#define ACCESSIBLE_OPTION_PANE L"option pane" + + /** + * A top level window with no title or border. + * see ACCESSIBLE_FRAME + * see ACCESSIBLE_DIALOG + */ +#define ACCESSIBLE_WINDOW L"window" + + /** + * A top level window with a title bar, border, menu bar, etc. It is + * often used as the primary window for an application. + * see ACCESSIBLE_DIALOG + * see ACCESSIBLE_CANVAS + * see ACCESSIBLE_WINDOW + */ +#define ACCESSIBLE_FRAME L"frame" + + /** + * A top level window with title bar and a border. A dialog is similar + * to a frame, but it has fewer properties and is often used as a + * secondary window for an application. + * see ACCESSIBLE_FRAME + * see ACCESSIBLE_WINDOW + */ +#define ACCESSIBLE_DIALOG L"dialog" + + /** + * A specialized dialog that lets the user choose a color. + */ +#define ACCESSIBLE_COLOR_CHOOSER L"color chooser" + + + /** + * A pane that allows the user to navigate through + * and select the contents of a directory. May be used + * by a file chooser. + * see ACCESSIBLE_FILE_CHOOSER + */ +#define ACCESSIBLE_DIRECTORY_PANE L"directory pane" + + /** + * A specialized dialog that displays the files in the directory + * and lets the user select a file, browse a different directory, + * or specify a filename. May use the directory pane to show the + * contents of a directory. + * see ACCESSIBLE_DIRECTORY_PANE + */ +#define ACCESSIBLE_FILE_CHOOSER L"file chooser" + + /** + * An object that fills up space in a user interface. It is often + * used in interfaces to tweak the spacing between components, + * but serves no other purpose. + */ +#define ACCESSIBLE_FILLER L"filler" + + /** + * A hypertext anchor + */ +#define ACCESSIBLE_HYPERLINK L"hyperlink" + + /** + * A small fixed size picture, typically used to decorate components. + */ +#define ACCESSIBLE_ICON L"icon" + + /** + * An object used to present an icon or short string in an interface. + */ +#define ACCESSIBLE_LABEL L"label" + + /** + * A specialized pane that has a glass pane and a layered pane as its + * children. + * see ACCESSIBLE_GLASS_PANE + * see ACCESSIBLE_LAYERED_PANE + */ +#define ACCESSIBLE_ROOT_PANE L"root pane" + + /** + * A pane that is guaranteed to be painted on top + * of all panes beneath it. + * see ACCESSIBLE_ROOT_PANE + * see ACCESSIBLE_CANVAS + */ +#define ACCESSIBLE_GLASS_PANE L"glass pane" + + /** + * A specialized pane that allows its children to be drawn in layers, + * providing a form of stacking order. This is usually the pane that + * holds the menu bar as well as the pane that contains most of the + * visual components in a window. + * see ACCESSIBLE_GLASS_PANE + * see ACCESSIBLE_ROOT_PANE + */ +#define ACCESSIBLE_LAYERED_PANE L"layered pane" + + /** + * An object that presents a list of objects to the user and allows the + * user to select one or more of them. A list is usually contained + * within a scroll pane. + * see ACCESSIBLE_SCROLL_PANE + * see ACCESSIBLE_LIST_ITEM + */ +#define ACCESSIBLE_LIST L"list" + + /** + * An object that presents an element in a list. A list is usually + * contained within a scroll pane. + * see ACCESSIBLE_SCROLL_PANE + * see ACCESSIBLE_LIST + */ +#define ACCESSIBLE_LIST_ITEM L"list item" + + /** + * An object usually drawn at the top of the primary dialog box of + * an application that contains a list of menus the user can choose + * from. For example, a menu bar might contain menus for "File," + * "Edit," and "Help." + * see ACCESSIBLE_MENU + * see ACCESSIBLE_POPUP_MENU + * see ACCESSIBLE_LAYERED_PANE + */ +#define ACCESSIBLE_MENU_BAR L"menu bar" + + /** + * A temporary window that is usually used to offer the user a + * list of choices, and then hides when the user selects one of + * those choices. + * see ACCESSIBLE_MENU + * see ACCESSIBLE_MENU_ITEM + */ +#define ACCESSIBLE_POPUP_MENU L"popup menu" + + /** + * An object usually found inside a menu bar that contains a list + * of actions the user can choose from. A menu can have any object + * as its children, but most often they are menu items, other menus, + * or rudimentary objects such as radio buttons, check boxes, or + * separators. For example, an application may have an "Edit" menu + * that contains menu items for "Cut" and "Paste." + * see ACCESSIBLE_MENU_BAR + * see ACCESSIBLE_MENU_ITEM + * see ACCESSIBLE_SEPARATOR + * see ACCESSIBLE_RADIO_BUTTON + * see ACCESSIBLE_CHECK_BOX + * see ACCESSIBLE_POPUP_MENU + */ +#define ACCESSIBLE_MENU L"menu" + + /** + * An object usually contained in a menu that presents an action + * the user can choose. For example, the "Cut" menu item in an + * "Edit" menu would be an action the user can select to cut the + * selected area of text in a document. + * see ACCESSIBLE_MENU_BAR + * see ACCESSIBLE_SEPARATOR + * see ACCESSIBLE_POPUP_MENU + */ +#define ACCESSIBLE_MENU_ITEM L"menu item" + + /** + * An object usually contained in a menu to provide a visual + * and logical separation of the contents in a menu. For example, + * the "File" menu of an application might contain menu items for + * "Open," "Close," and "Exit," and will place a separator between + * "Close" and "Exit" menu items. + * see ACCESSIBLE_MENU + * see ACCESSIBLE_MENU_ITEM + */ +#define ACCESSIBLE_SEPARATOR L"separator" + + /** + * An object that presents a series of panels (or page tabs), one at a + * time, through some mechanism provided by the object. The most common + * mechanism is a list of tabs at the top of the panel. The children of + * a page tab list are all page tabs. + * see ACCESSIBLE_PAGE_TAB + */ +#define ACCESSIBLE_PAGE_TAB_LIST L"page tab list" + + /** + * An object that is a child of a page tab list. Its sole child is + * the panel that is to be presented to the user when the user + * selects the page tab from the list of tabs in the page tab list. + * see ACCESSIBLE_PAGE_TAB_LIST + */ +#define ACCESSIBLE_PAGE_TAB L"page tab" + + /** + * A generic container that is often used to group objects. + */ +#define ACCESSIBLE_PANEL L"panel" + + /** + * An object used to indicate how much of a task has been completed. + */ +#define ACCESSIBLE_PROGRESS_BAR L"progress bar" + + /** + * A text object used for passwords, or other places where the + * text contents is not shown visibly to the user + */ +#define ACCESSIBLE_PASSWORD_TEXT L"password text" + + /** + * An object the user can manipulate to tell the application to do + * something. + * see ACCESSIBLE_CHECK_BOX + * see ACCESSIBLE_TOGGLE_BUTTON + * see ACCESSIBLE_RADIO_BUTTON + */ +#define ACCESSIBLE_PUSH_BUTTON L"push button" + + /** + * A specialized push button that can be checked or unchecked, but + * does not provide a separate indicator for the current state. + * see ACCESSIBLE_PUSH_BUTTON + * see ACCESSIBLE_CHECK_BOX + * see ACCESSIBLE_RADIO_BUTTON + */ +#define ACCESSIBLE_TOGGLE_BUTTON L"toggle button" + + /** + * A choice that can be checked or unchecked and provides a + * separate indicator for the current state. + * see ACCESSIBLE_PUSH_BUTTON + * see ACCESSIBLE_TOGGLE_BUTTON + * see ACCESSIBLE_RADIO_BUTTON + */ +#define ACCESSIBLE_CHECK_BOX L"check box" + + /** + * A specialized check box that will cause other radio buttons in the + * same group to become unchecked when this one is checked. + * see ACCESSIBLE_PUSH_BUTTON + * see ACCESSIBLE_TOGGLE_BUTTON + * see ACCESSIBLE_CHECK_BOX + */ +#define ACCESSIBLE_RADIO_BUTTON L"radio button" + + /** + * The header for a row of data. + */ +#define ACCESSIBLE_ROW_HEADER L"row header" + + /** + * An object that allows a user to incrementally view a large amount + * of information. Its children can include scroll bars and a viewport. + * see ACCESSIBLE_SCROLL_BAR + * see ACCESSIBLE_VIEWPORT + */ +#define ACCESSIBLE_SCROLL_PANE L"scroll pane" + + /** + * An object usually used to allow a user to incrementally view a + * large amount of data. Usually used only by a scroll pane. + * see ACCESSIBLE_SCROLL_PANE + */ +#define ACCESSIBLE_SCROLL_BAR L"scroll bar" + + /** + * An object usually used in a scroll pane. It represents the portion + * of the entire data that the user can see. As the user manipulates + * the scroll bars, the contents of the viewport can change. + * see ACCESSIBLE_SCROLL_PANE + */ +#define ACCESSIBLE_VIEWPORT L"viewport" + + /** + * An object that allows the user to select from a bounded range. For + * example, a slider might be used to select a number between 0 and 100. + */ +#define ACCESSIBLE_SLIDER L"slider" + + /** + * A specialized panel that presents two other panels at the same time. + * Between the two panels is a divider the user can manipulate to make + * one panel larger and the other panel smaller. + */ +#define ACCESSIBLE_SPLIT_PANE L"split pane" + + /** + * An object used to present information in terms of rows and columns. + * An example might include a spreadsheet application. + */ +#define ACCESSIBLE_TABLE L"table" + + /** + * An object that presents text to the user. The text is usually + * editable by the user as opposed to a label. + * see ACCESSIBLE_LABEL + */ +#define ACCESSIBLE_TEXT L"text" + + /** + * An object used to present hierarchical information to the user. + * The individual nodes in the tree can be collapsed and expanded + * to provide selective disclosure of the tree's contents. + */ +#define ACCESSIBLE_TREE L"tree" + + /** + * A bar or palette usually composed of push buttons or toggle buttons. + * It is often used to provide the most frequently used functions for an + * application. + */ +#define ACCESSIBLE_TOOL_BAR L"tool bar" + + /** + * An object that provides information about another object. The + * accessibleDescription property of the tool tip is often displayed + * to the user in a small L"help bubble" when the user causes the + * mouse to hover over the object associated with the tool tip. + */ +#define ACCESSIBLE_TOOL_TIP L"tool tip" + + /** + * An AWT component, but nothing else is known about it. + * see ACCESSIBLE_SWING_COMPONENT + * see ACCESSIBLE_UNKNOWN + */ +#define ACCESSIBLE_AWT_COMPONENT L"awt component" + + /** + * A Swing component, but nothing else is known about it. + * see ACCESSIBLE_AWT_COMPONENT + * see ACCESSIBLE_UNKNOWN + */ +#define ACCESSIBLE_SWING_COMPONENT L"swing component" + + /** + * The object contains some Accessible information, but its role is + * not known. + * see ACCESSIBLE_AWT_COMPONENT + * see ACCESSIBLE_SWING_COMPONENT + */ +#define ACCESSIBLE_UNKNOWN L"unknown" + + /** + * A STATUS_BAR is an simple component that can contain + * multiple labels of status information to the user. + */ +#define ACCESSIBLE_STATUS_BAR L"status bar" + + /** + * A DATE_EDITOR is a component that allows users to edit + * java.util.Date and java.util.Time objects + */ +#define ACCESSIBLE_DATE_EDITOR L"date editor" + + /** + * A SPIN_BOX is a simple spinner component and its main use + * is for simple numbers. + */ +#define ACCESSIBLE_SPIN_BOX L"spin box" + + /** + * A FONT_CHOOSER is a component that lets the user pick various + * attributes for fonts. + */ +#define ACCESSIBLE_FONT_CHOOSER L"font chooser" + + /** + * A GROUP_BOX is a simple container that contains a border + * around it and contains components inside it. + */ +#define ACCESSIBLE_GROUP_BOX L"group box" + + /** + * A text header + */ +#define ACCESSIBLE_HEADER L"header" + + /** + * A text footer + */ +#define ACCESSIBLE_FOOTER L"footer" + + /** + * A text paragraph + */ +#define ACCESSIBLE_PARAGRAPH L"paragraph" + + /** + * A ruler is an object used to measure distance + */ +#define ACCESSIBLE_RULER L"ruler" + + /** + * A role indicating the object acts as a formula for + * calculating a value. An example is a formula in + * a spreadsheet cell. + */ +#define ACCESSIBLE_EDITBAR L"editbar" + + /** + * A role indicating the object monitors the progress + * of some operation. + */ +#define PROGRESS_MONITOR L"progress monitor" + + + /** + ****************************************************** + * Accessibility event types + ****************************************************** + */ + +#define cPropertyNameChangeEvent (jlong) 1 // 1 +#define cPropertyDescriptionChangeEvent (jlong) 2 // 2 +#define cPropertyStateChangeEvent (jlong) 4 // 4 +#define cPropertyValueChangeEvent (jlong) 8 // 8 +#define cPropertySelectionChangeEvent (jlong) 16 // 10 +#define cPropertyTextChangeEvent (jlong) 32 // 20 +#define cPropertyCaretChangeEvent (jlong) 64 // 40 +#define cPropertyVisibleDataChangeEvent (jlong) 128 // 80 +#define cPropertyChildChangeEvent (jlong) 256 // 100 +#define cPropertyActiveDescendentChangeEvent (jlong) 512 // 200 +#define cPropertyTableModelChangeEvent (jlong) 1024 // 400 + + /** + ****************************************************** + * optional AccessibleContext interfaces + * + * This version of the bridge reuses the accessibleValue + * field in the AccessibleContextInfo struct to represent + * additional optional interfaces that are supported by + * the Java AccessibleContext. This is backwardly compatable + * because the old accessibleValue was set to the BOOL + * value TRUE (i.e., 1) if the AccessibleValue interface is + * supported. + ****************************************************** + */ + +#define cAccessibleValueInterface (jlong) 1 // 1 << 1 (TRUE) +#define cAccessibleActionInterface (jlong) 2 // 1 << 2 +#define cAccessibleComponentInterface (jlong) 4 // 1 << 3 +#define cAccessibleSelectionInterface (jlong) 8 // 1 << 4 +#define cAccessibleTableInterface (jlong) 16 // 1 << 5 +#define cAccessibleTextInterface (jlong) 32 // 1 << 6 +#define cAccessibleHypertextInterface (jlong) 64 // 1 << 7 + + + /** + ****************************************************** + * Accessibility information bundles + ****************************************************** + */ + + typedef struct AccessBridgeVersionInfoTag { + wchar_t VMversion[SHORT_STRING_SIZE]; // output of "java -version" + wchar_t bridgeJavaClassVersion[SHORT_STRING_SIZE]; // version of the AccessBridge.class + wchar_t bridgeJavaDLLVersion[SHORT_STRING_SIZE]; // version of JavaAccessBridge.dll + wchar_t bridgeWinDLLVersion[SHORT_STRING_SIZE]; // version of WindowsAccessBridge.dll + } AccessBridgeVersionInfo; + + + typedef struct AccessibleContextInfoTag { + wchar_t name[MAX_STRING_SIZE]; // the AccessibleName of the object + wchar_t description[MAX_STRING_SIZE]; // the AccessibleDescription of the object + + wchar_t role[SHORT_STRING_SIZE]; // localized AccesibleRole string + wchar_t role_en_US[SHORT_STRING_SIZE]; // AccesibleRole string in the en_US locale + wchar_t states[SHORT_STRING_SIZE]; // localized AccesibleStateSet string (comma separated) + wchar_t states_en_US[SHORT_STRING_SIZE]; // AccesibleStateSet string in the en_US locale (comma separated) + + jint indexInParent; // index of object in parent + jint childrenCount; // # of children, if any + + jint x; // screen coords in pixels + jint y; // " + jint width; // pixel width of object + jint height; // pixel height of object + + BOOL accessibleComponent; // flags for various additional + BOOL accessibleAction; // Java Accessibility interfaces + BOOL accessibleSelection; // FALSE if this object doesn't + BOOL accessibleText; // implement the additional interface + // in question + + // BOOL accessibleValue; // old BOOL indicating whether AccessibleValue is supported + BOOL accessibleInterfaces; // new bitfield containing additional interface flags + + } AccessibleContextInfo; + + + + // AccessibleText packages + typedef struct AccessibleTextInfoTag { + jint charCount; // # of characters in this text object + jint caretIndex; // index of caret + jint indexAtPoint; // index at the passsed in point + } AccessibleTextInfo; + + typedef struct AccessibleTextItemsInfoTag { + wchar_t letter; + wchar_t word[SHORT_STRING_SIZE]; + wchar_t sentence[MAX_STRING_SIZE]; + } AccessibleTextItemsInfo; + + typedef struct AccessibleTextSelectionInfoTag { + jint selectionStartIndex; + jint selectionEndIndex; + wchar_t selectedText[MAX_STRING_SIZE]; + } AccessibleTextSelectionInfo; + + typedef struct AccessibleTextRectInfoTag { + jint x; // bounding rect of char at index + jint y; // " + jint width; // " + jint height; // " + } AccessibleTextRectInfo; + + // standard attributes for text; note: tabstops are not supported + typedef struct AccessibleTextAttributesInfoTag { + BOOL bold; + BOOL italic; + BOOL underline; + BOOL strikethrough; + BOOL superscript; + BOOL subscript; + + wchar_t backgroundColor[SHORT_STRING_SIZE]; + wchar_t foregroundColor[SHORT_STRING_SIZE]; + wchar_t fontFamily[SHORT_STRING_SIZE]; + jint fontSize; + + jint alignment; + jint bidiLevel; + + jfloat firstLineIndent; + jfloat leftIndent; + jfloat rightIndent; + jfloat lineSpacing; + jfloat spaceAbove; + jfloat spaceBelow; + + wchar_t fullAttributesString[MAX_STRING_SIZE]; + } AccessibleTextAttributesInfo; + + /** + ****************************************************** + * IPC management typedefs + ****************************************************** + */ + +#define cMemoryMappedNameSize 255 + + /** + * sent by the WindowsDLL -> the memory-mapped file is setup + * + */ + typedef struct MemoryMappedFileCreatedPackageTag { +// HWND bridgeWindow; // redundant, but easier to get to here... + ABHWND64 bridgeWindow; // redundant, but easier to get to here... + char filename[cMemoryMappedNameSize]; + } MemoryMappedFileCreatedPackage; + + + + + /** + * sent when a new JavaVM attaches to the Bridge + * + */ + typedef struct JavaVMCreatedPackageTag { + ABHWND64 bridgeWindow; + long vmID; + } JavaVMCreatedPackage; + + /** + * sent when a JavaVM detatches from the Bridge + * + */ + typedef struct JavaVMDestroyedPackageTag { + ABHWND64 bridgeWindow; + } JavaVMDestroyedPackage; + + /** + * sent when a new AT attaches to the Bridge + * + */ + typedef struct WindowsATCreatedPackageTag { + ABHWND64 bridgeWindow; + } WindowsATCreatedPackage; + + /** + * sent when an AT detatches from the Bridge + * + */ + typedef struct WindowsATDestroyedPackageTag { + ABHWND64 bridgeWindow; + } WindowsATDestroyedPackage; + + + /** + * sent by JVM Bridges in response to a WindowsATCreate + * message; saying "howdy, welcome to the neighborhood" + * + */ + typedef struct JavaVMPresentNotificationPackageTag { + ABHWND64 bridgeWindow; + long vmID; + } JavaVMPresentNotificationPackage; + + /** + * sent by AT Bridges in response to a JavaVMCreate + * message; saying "howdy, welcome to the neighborhood" + * + */ + typedef struct WindowsATPresentNotificationPackageTag { + ABHWND64 bridgeWindow; + } WindowsATPresentNotificationPackage; + + + /** + ****************************************************** + * Core packages + ****************************************************** + */ + + typedef struct ReleaseJavaObjectPackageTag { + long vmID; + JOBJECT64 object; + } ReleaseJavaObjectPackage; + + typedef struct GetAccessBridgeVersionPackageTag { + long vmID; // can't get VM info w/out a VM! + AccessBridgeVersionInfo rVersionInfo; + } GetAccessBridgeVersionPackage; + + typedef struct IsSameObjectPackageTag { + long vmID; + JOBJECT64 obj1; + JOBJECT64 obj2; + jboolean rResult; + } IsSameObjectPackage; + + /** + ****************************************************** + * Windows packages + ****************************************************** + */ + + typedef struct IsJavaWindowPackageTag { + jint window; + jboolean rResult; + } IsJavaWindowPackage; + + typedef struct GetAccessibleContextFromHWNDPackageTag { + jint window; + long rVMID; + JOBJECT64 rAccessibleContext; + } GetAccessibleContextFromHWNDPackage; + + typedef struct GetHWNDFromAccessibleContextPackageTag { + JOBJECT64 accessibleContext; + ABHWND64 rHWND; + } GetHWNDFromAccessibleContextPackage; + + /** +****************************************************** +* AccessibleContext packages +****************************************************** +*/ + + typedef struct GetAccessibleContextAtPackageTag { + jint x; + jint y; + long vmID; + JOBJECT64 AccessibleContext; // look within this AC + JOBJECT64 rAccessibleContext; + } GetAccessibleContextAtPackage; + + typedef struct GetAccessibleContextWithFocusPackageTag { + long rVMID; + JOBJECT64 rAccessibleContext; + } GetAccessibleContextWithFocusPackage; + + typedef struct GetAccessibleContextInfoPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + AccessibleContextInfo rAccessibleContextInfo; + } GetAccessibleContextInfoPackage; + + typedef struct GetAccessibleChildFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint childIndex; + JOBJECT64 rAccessibleContext; + } GetAccessibleChildFromContextPackage; + + typedef struct GetAccessibleParentFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + JOBJECT64 rAccessibleContext; + } GetAccessibleParentFromContextPackage; + + /** +****************************************************** +* AccessibleTable packages +****************************************************** +*/ + +#define MAX_TABLE_SELECTIONS 64 + + // table information + typedef struct AccessibleTableInfoTag { + JOBJECT64 caption; // AccesibleContext + JOBJECT64 summary; // AccessibleContext + jint rowCount; + jint columnCount; + JOBJECT64 accessibleContext; + JOBJECT64 accessibleTable; + } AccessibleTableInfo; + + typedef struct GetAccessibleTableInfoPackageTag { + long vmID; + JOBJECT64 accessibleContext; + AccessibleTableInfo rTableInfo; + } GetAccessibleTableInfoPackage; + + // table cell information + typedef struct AccessibleTableCellInfoTag { + JOBJECT64 accessibleContext; + jint index; + jint row; + jint column; + jint rowExtent; + jint columnExtent; + jboolean isSelected; + } AccessibleTableCellInfo; + + typedef struct GetAccessibleTableCellInfoPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint row; + jint column; + AccessibleTableCellInfo rTableCellInfo; + } GetAccessibleTableCellInfoPackage; + + typedef struct GetAccessibleTableRowHeaderPackageTag { + long vmID; + JOBJECT64 accessibleContext; + AccessibleTableInfo rTableInfo; + } GetAccessibleTableRowHeaderPackage; + + typedef struct GetAccessibleTableColumnHeaderPackageTag { + long vmID; + JOBJECT64 accessibleContext; + AccessibleTableInfo rTableInfo; + } GetAccessibleTableColumnHeaderPackage; + + typedef struct GetAccessibleTableRowDescriptionPackageTag { + long vmID; + JOBJECT64 accessibleContext; + jint row; + JOBJECT64 rAccessibleContext; + } GetAccessibleTableRowDescriptionPackage; + + typedef struct GetAccessibleTableColumnDescriptionPackageTag { + long vmID; + JOBJECT64 accessibleContext; + jint column; + JOBJECT64 rAccessibleContext; + } GetAccessibleTableColumnDescriptionPackage; + + typedef struct GetAccessibleTableRowSelectionCountPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint rCount; + } GetAccessibleTableRowSelectionCountPackage; + + typedef struct IsAccessibleTableRowSelectedPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint row; + jboolean rResult; + } IsAccessibleTableRowSelectedPackage; + + typedef struct GetAccessibleTableRowSelectionsPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint count; + jint rSelections[MAX_TABLE_SELECTIONS]; + } GetAccessibleTableRowSelectionsPackage; + + typedef struct GetAccessibleTableColumnSelectionCountPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint rCount; + } GetAccessibleTableColumnSelectionCountPackage; + + typedef struct IsAccessibleTableColumnSelectedPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint column; + jboolean rResult; + } IsAccessibleTableColumnSelectedPackage; + + typedef struct GetAccessibleTableColumnSelectionsPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint count; + jint rSelections[MAX_TABLE_SELECTIONS]; + } GetAccessibleTableColumnSelectionsPackage; + + + typedef struct GetAccessibleTableRowPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint index; + jint rRow; + } GetAccessibleTableRowPackage; + + typedef struct GetAccessibleTableColumnPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint index; + jint rColumn; + } GetAccessibleTableColumnPackage; + + typedef struct GetAccessibleTableIndexPackageTag { + long vmID; + JOBJECT64 accessibleTable; + jint row; + jint column; + jint rIndex; + } GetAccessibleTableIndexPackage; + + + /** + ****************************************************** + * AccessibleRelationSet packages + ****************************************************** + */ + +#define MAX_RELATION_TARGETS 25 +#define MAX_RELATIONS 5 + + typedef struct AccessibleRelationInfoTag { + wchar_t key[SHORT_STRING_SIZE]; + jint targetCount; + JOBJECT64 targets[MAX_RELATION_TARGETS]; // AccessibleContexts + } AccessibleRelationInfo; + + typedef struct AccessibleRelationSetInfoTag { + jint relationCount; + AccessibleRelationInfo relations[MAX_RELATIONS]; + } AccessibleRelationSetInfo; + + typedef struct GetAccessibleRelationSetPackageTag { + long vmID; + JOBJECT64 accessibleContext; + AccessibleRelationSetInfo rAccessibleRelationSetInfo; + } GetAccessibleRelationSetPackage; + + /** + ****************************************************** + * AccessibleHypertext packagess + ****************************************************** + */ + +#define MAX_HYPERLINKS 64 // maximum number of hyperlinks returned + + // hyperlink information + typedef struct AccessibleHyperlinkInfoTag { + wchar_t text[SHORT_STRING_SIZE]; // the hyperlink text + jint startIndex; //index in the hypertext document where the link begins + jint endIndex; //index in the hypertext document where the link ends + JOBJECT64 accessibleHyperlink; // AccessibleHyperlink object + } AccessibleHyperlinkInfo; + + // hypertext information + typedef struct AccessibleHypertextInfoTag { + jint linkCount; // number of hyperlinks + AccessibleHyperlinkInfo links[MAX_HYPERLINKS]; // the hyperlinks + JOBJECT64 accessibleHypertext; // AccessibleHypertext object + } AccessibleHypertextInfo; + + // struct for sending a message to get the hypertext for an AccessibleContext + typedef struct GetAccessibleHypertextPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // AccessibleContext with hypertext + AccessibleHypertextInfo rAccessibleHypertextInfo; // returned hypertext + } GetAccessibleHypertextPackage; + + // struct for sending an message to activate a hyperlink + typedef struct ActivateAccessibleHyperlinkPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // AccessibleContext containing the link + JOBJECT64 accessibleHyperlink; // the link to activate + BOOL rResult; // hyperlink activation return value + } ActivateAccessibleHyperlinkPackage; + + // struct for sending a message to get the number of hyperlinks in a component + typedef struct GetAccessibleHyperlinkCountPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // AccessibleContext containing AccessibleHypertext + jint rLinkCount; // link count return value + } GetAccessibleHyperlinkCountPackage; + + // struct for sending a message to get the hypertext for an AccessibleContext + // starting at a specified index in the document + typedef struct GetAccessibleHypertextExtPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // AccessibleContext with hypertext + jint startIndex; // start index in document + AccessibleHypertextInfo rAccessibleHypertextInfo; // returned hypertext + BOOL rSuccess; // whether call succeeded + } GetAccessibleHypertextExtPackage; + + // struct for sending a message to get the nth hyperlink in a document; + // maps to AccessibleHypertext.getLink + typedef struct GetAccessibleHyperlinkPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 hypertext; // AccessibleHypertext + jint linkIndex; // hyperlink index + AccessibleHyperlinkInfo rAccessibleHyperlinkInfo; // returned hyperlink + } GetAccessibleHyperlinkPackage; + + // struct for sending a message to get the index into an array + // of hyperlinks that is associated with a character index in a + // document; maps to AccessibleHypertext.getLinkIndex + typedef struct GetAccessibleHypertextLinkIndexPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 hypertext; // AccessibleHypertext + jint charIndex; // character index in document + jint rLinkIndex; // returned hyperlink index + } GetAccessibleHypertextLinkIndexPackage; + + /** + ****************************************************** + * Accessible Key Bindings packages + ****************************************************** + */ + +#define MAX_KEY_BINDINGS 10 + + // keyboard character modifiers +#define ACCESSIBLE_SHIFT_KEYSTROKE 1 +#define ACCESSIBLE_CONTROL_KEYSTROKE 2 +#define ACCESSIBLE_META_KEYSTROKE 4 +#define ACCESSIBLE_ALT_KEYSTROKE 8 +#define ACCESSIBLE_ALT_GRAPH_KEYSTROKE 16 +#define ACCESSIBLE_BUTTON1_KEYSTROKE 32 +#define ACCESSIBLE_BUTTON2_KEYSTROKE 64 +#define ACCESSIBLE_BUTTON3_KEYSTROKE 128 +#define ACCESSIBLE_FKEY_KEYSTROKE 256 // F key pressed, character contains 1-24 +#define ACCESSIBLE_CONTROLCODE_KEYSTROKE 512 // Control code key pressed, character contains control code. + +// The supported control code keys are: +#define ACCESSIBLE_VK_BACK_SPACE 8 +#define ACCESSIBLE_VK_DELETE 127 +#define ACCESSIBLE_VK_DOWN 40 +#define ACCESSIBLE_VK_END 35 +#define ACCESSIBLE_VK_HOME 36 +#define ACCESSIBLE_VK_INSERT 155 +#define ACCESSIBLE_VK_KP_DOWN 225 +#define ACCESSIBLE_VK_KP_LEFT 226 +#define ACCESSIBLE_VK_KP_RIGHT 227 +#define ACCESSIBLE_VK_KP_UP 224 +#define ACCESSIBLE_VK_LEFT 37 +#define ACCESSIBLE_VK_PAGE_DOWN 34 +#define ACCESSIBLE_VK_PAGE_UP 33 +#define ACCESSIBLE_VK_RIGHT 39 +#define ACCESSIBLE_VK_UP 38 + + // a key binding associates with a component + typedef struct AccessibleKeyBindingInfoTag { + jchar character; // the key character + jint modifiers; // the key modifiers + } AccessibleKeyBindingInfo; + + // all of the key bindings associated with a component + typedef struct AccessibleKeyBindingsTag { + int keyBindingsCount; // number of key bindings + AccessibleKeyBindingInfo keyBindingInfo[MAX_KEY_BINDINGS]; + } AccessibleKeyBindings; + + // struct to get the key bindings associated with a component + typedef struct GetAccessibleKeyBindingsPackageTag { + long vmID; // the virtual machine id + JOBJECT64 accessibleContext; // the component + AccessibleKeyBindings rAccessibleKeyBindings; // the key bindings + } GetAccessibleKeyBindingsPackage; + + /** +****************************************************** +* AccessibleIcon packages +****************************************************** +*/ +#define MAX_ICON_INFO 8 + + // an icon assocated with a component + typedef struct AccessibleIconInfoTag { + wchar_t description[SHORT_STRING_SIZE]; // icon description + jint height; // icon height + jint width; // icon width + } AccessibleIconInfo; + + // all of the icons associated with a component + typedef struct AccessibleIconsTag { + jint iconsCount; // number of icons + AccessibleIconInfo iconInfo[MAX_ICON_INFO]; // the icons + } AccessibleIcons; + + // struct to get the icons associated with a component + typedef struct GetAccessibleIconsPackageTag { + long vmID; // the virtual machine id + JOBJECT64 accessibleContext; // the component + AccessibleIcons rAccessibleIcons; // the icons + } GetAccessibleIconsPackage; + + + /** +****************************************************** +* AccessibleAction packages +****************************************************** +*/ +#define MAX_ACTION_INFO 256 +#define MAX_ACTIONS_TO_DO 32 + + // an action assocated with a component + typedef struct AccessibleActionInfoTag { + wchar_t name[SHORT_STRING_SIZE]; // action name + } AccessibleActionInfo; + + // all of the actions associated with a component + typedef struct AccessibleActionsTag { + jint actionsCount; // number of actions + AccessibleActionInfo actionInfo[MAX_ACTION_INFO]; // the action information + } AccessibleActions; + + // struct for requesting the actions associated with a component + typedef struct GetAccessibleActionsPackageTag { + long vmID; + JOBJECT64 accessibleContext; // the component + AccessibleActions rAccessibleActions; // the actions + } GetAccessibleActionsPackage; + + // list of AccessibleActions to do + typedef struct AccessibleActionsToDoTag { + jint actionsCount; // number of actions to do + AccessibleActionInfo actions[MAX_ACTIONS_TO_DO];// the accessible actions to do + } AccessibleActionsToDo; + + // struct for sending an message to do one or more actions + typedef struct DoAccessibleActionsPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // component to do the action + AccessibleActionsToDo actionsToDo; // the accessible actions to do + BOOL rResult; // action return value + jint failure; // index of action that failed if rResult is FALSE + } DoAccessibleActionsPackage; + + /** +****************************************************** +* AccessibleText packages +****************************************************** +*/ + + typedef struct GetAccessibleTextInfoPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint x; + jint y; + AccessibleTextInfo rTextInfo; + } GetAccessibleTextInfoPackage; + + typedef struct GetAccessibleTextItemsPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + AccessibleTextItemsInfo rTextItemsInfo; + } GetAccessibleTextItemsPackage; + + typedef struct GetAccessibleTextSelectionInfoPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + AccessibleTextSelectionInfo rTextSelectionItemsInfo; + } GetAccessibleTextSelectionInfoPackage; + + typedef struct GetAccessibleTextAttributeInfoPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + AccessibleTextAttributesInfo rAttributeInfo; + } GetAccessibleTextAttributeInfoPackage; + + typedef struct GetAccessibleTextRectInfoPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + AccessibleTextRectInfo rTextRectInfo; + } GetAccessibleTextRectInfoPackage; + + typedef struct GetCaretLocationPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + AccessibleTextRectInfo rTextRectInfo; + } GetCaretLocationPackage; + + typedef struct GetAccessibleTextLineBoundsPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + jint rLineStart; + jint rLineEnd; + } GetAccessibleTextLineBoundsPackage; + + typedef struct GetAccessibleTextRangePackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint start; + jint end; + wchar_t rText[MAX_BUFFER_SIZE]; + } GetAccessibleTextRangePackage; + + /** +****************************************************** +* +* Utility method packages +****************************************************** +*/ + + typedef struct SetTextContentsPackageTag { + long vmID; + JOBJECT64 accessibleContext; // the text field + wchar_t text[MAX_STRING_SIZE]; // the text + BOOL rResult; + } SetTextContentsPackage; + + typedef struct GetParentWithRolePackageTag { + long vmID; + JOBJECT64 accessibleContext; + wchar_t role[SHORT_STRING_SIZE]; // one of Accessible Roles above + JOBJECT64 rAccessibleContext; + } GetParentWithRolePackage; + + typedef struct GetTopLevelObjectPackageTag { + long vmID; + JOBJECT64 accessibleContext; + JOBJECT64 rAccessibleContext; + } GetTopLevelObjectPackage; + + typedef struct GetParentWithRoleElseRootPackageTag { + long vmID; + JOBJECT64 accessibleContext; + wchar_t role[SHORT_STRING_SIZE]; // one of Accessible Roles above + JOBJECT64 rAccessibleContext; + } GetParentWithRoleElseRootPackage; + + typedef struct GetObjectDepthPackageTag { + long vmID; + JOBJECT64 accessibleContext; + jint rResult; + } GetObjectDepthPackage; + + typedef struct GetActiveDescendentPackageTag { + long vmID; + JOBJECT64 accessibleContext; + JOBJECT64 rAccessibleContext; + } GetActiveDescendentPackage; + + /** +****************************************************** +* AccessibleValue packages +****************************************************** +*/ + + typedef struct GetCurrentAccessibleValueFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + wchar_t rValue[SHORT_STRING_SIZE]; + } GetCurrentAccessibleValueFromContextPackage; + + typedef struct GetMaximumAccessibleValueFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + wchar_t rValue[SHORT_STRING_SIZE]; + } GetMaximumAccessibleValueFromContextPackage; + + typedef struct GetMinimumAccessibleValueFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + wchar_t rValue[SHORT_STRING_SIZE]; + } GetMinimumAccessibleValueFromContextPackage; + + + /** +****************************************************** +* AccessibleSelection packages +****************************************************** +*/ + + typedef struct AddAccessibleSelectionFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + } AddAccessibleSelectionFromContextPackage; + + typedef struct ClearAccessibleSelectionFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + } ClearAccessibleSelectionFromContextPackage; + + typedef struct GetAccessibleSelectionFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + JOBJECT64 rAccessibleContext; + } GetAccessibleSelectionFromContextPackage; + + typedef struct GetAccessibleSelectionCountFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint rCount; + } GetAccessibleSelectionCountFromContextPackage; + + typedef struct IsAccessibleChildSelectedFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + jboolean rResult; + } IsAccessibleChildSelectedFromContextPackage; + + typedef struct RemoveAccessibleSelectionFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + jint index; + } RemoveAccessibleSelectionFromContextPackage; + + typedef struct SelectAllAccessibleSelectionFromContextPackageTag { + long vmID; + JOBJECT64 AccessibleContext; + } SelectAllAccessibleSelectionFromContextPackage; + + + /** +****************************************************** +* Java Event Notification Registration packages +****************************************************** +*/ + + typedef struct AddJavaEventNotificationPackageTag { + jlong type; + //HWND DLLwindow; + ABHWND64 DLLwindow; + } AddJavaEventNotificationPackage; + + typedef struct RemoveJavaEventNotificationPackageTag { + jlong type; + //HWND DLLwindow; + ABHWND64 DLLwindow; + } RemoveJavaEventNotificationPackage; + + + /** +****************************************************** +* Accessibility Event Notification Registration packages +****************************************************** +*/ + + typedef struct AddAccessibilityEventNotificationPackageTag { + jlong type; + //HWND DLLwindow; + ABHWND64 DLLwindow; + } AddAccessibilityEventNotificationPackage; + + typedef struct RemoveAccessibilityEventNotificationPackageTag { + jlong type; + //HWND DLLwindow; + ABHWND64 DLLwindow; + } RemoveAccessibilityEventNotificationPackage; + + + /** +****************************************************** +* Accessibility Property Change Event packages +****************************************************** +*/ + + typedef struct PropertyCaretChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + jint oldPosition; + jint newPosition; + } PropertyCaretChangePackage; + + typedef struct PropertyDescriptionChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + wchar_t oldDescription[SHORT_STRING_SIZE]; + wchar_t newDescription[SHORT_STRING_SIZE]; + } PropertyDescriptionChangePackage; + + typedef struct PropertyNameChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + wchar_t oldName[SHORT_STRING_SIZE]; + wchar_t newName[SHORT_STRING_SIZE]; + } PropertyNameChangePackage; + + typedef struct PropertySelectionChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } PropertySelectionChangePackage; + + typedef struct PropertyStateChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + wchar_t oldState[SHORT_STRING_SIZE]; + wchar_t newState[SHORT_STRING_SIZE]; + } PropertyStateChangePackage; + + typedef struct PropertyTextChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } PropertyTextChangePackage; + + typedef struct PropertyValueChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + wchar_t oldValue[SHORT_STRING_SIZE]; + wchar_t newValue[SHORT_STRING_SIZE]; + } PropertyValueChangePackage; + + typedef struct PropertyVisibleDataChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } PropertyVisibleDataChangePackage; + + typedef struct PropertyChildChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + JOBJECT64 oldChildAccessibleContext; + JOBJECT64 newChildAccessibleContext; + } PropertyChildChangePackage; + + typedef struct PropertyActiveDescendentChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + JOBJECT64 oldActiveDescendentAccessibleContext; + JOBJECT64 newActiveDescendentAccessibleContext; + } PropertyActiveDescendentChangePackage; + + + // String format for newValue is: + // "type" one of "INSERT", "UPDATE" or "DELETE" + // "firstRow" + // "lastRow" + // "firstColumn" + // "lastColumn" + // + // oldValue is currently unused + // + typedef struct PropertyTableModelChangePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + wchar_t oldValue[SHORT_STRING_SIZE]; + wchar_t newValue[SHORT_STRING_SIZE]; + } PropertyTableModelChangePackage; + + + /** +****************************************************** +* Property Change Event packages +****************************************************** +*/ + + /* + typedef struct PropertyChangePackageTag { + long vmID; + jobject Event; + jobject AccessibleContextSource; + char propertyName[SHORT_STRING_SIZE]; + char oldValue[SHORT_STRING_SIZE]; // PropertyChangeEvent().getOldValue().toString() + char newValue[SHORT_STRING_SIZE]; // PropertyChangeEvent().getNewValue().toString() + } PropertyChangePackage; + */ + + /* + * Java shutdown event package + */ + typedef struct JavaShutdownPackageTag { + long vmID; + } JavaShutdownPackage; + + + /** +****************************************************** +* Focus Event packages +****************************************************** +*/ + + typedef struct FocusGainedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } FocusGainedPackage; + + typedef struct FocusLostPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } FocusLostPackage; + + + /** +****************************************************** +* Caret Event packages +****************************************************** +*/ + + typedef struct CaretUpdatePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } CaretUpdatePackage; + + + /** +****************************************************** +* Mouse Event packages +****************************************************** +*/ + + typedef struct MouseClickedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MouseClickedPackage; + + typedef struct MouseEnteredPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MouseEnteredPackage; + + typedef struct MouseExitedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MouseExitedPackage; + + typedef struct MousePressedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MousePressedPackage; + + typedef struct MouseReleasedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MouseReleasedPackage; + + + /** +****************************************************** +* Menu/PopupMenu Event packages +****************************************************** +*/ + + typedef struct MenuCanceledPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MenuCanceledPackage; + + typedef struct MenuDeselectedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MenuDeselectedPackage; + + typedef struct MenuSelectedPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } MenuSelectedPackage; + + + typedef struct PopupMenuCanceledPackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } PopupMenuCanceledPackage; + + typedef struct PopupMenuWillBecomeInvisiblePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } PopupMenuWillBecomeInvisiblePackage; + + typedef struct PopupMenuWillBecomeVisiblePackageTag { + long vmID; + JOBJECT64 Event; + JOBJECT64 AccessibleContextSource; + } PopupMenuWillBecomeVisiblePackage; + + /** +****************************************************** +* Additional methods for Teton +****************************************************** +*/ + + /** + * Gets the AccessibleName for a component based upon the JAWS algorithm. Returns + * whether successful. + * + * Bug ID 4916682 - Implement JAWS AccessibleName policy + */ + typedef struct GetVirtualAccessibleNamePackageTag { + long vmID; + AccessibleContext accessibleContext; + wchar_t rName[MAX_STRING_SIZE]; + int len; + } GetVirtualAccessibleNamePackage; + + /** + * Request focus for a component. Returns whether successful; + * + * Bug ID 4944757 - requestFocus method needed + */ + typedef struct RequestFocusPackageTag { + long vmID; + AccessibleContext accessibleContext; + } RequestFocusPackage; + + /** + * Selects text between two indices. Selection includes the text at the start index + * and the text at the end index. Returns whether successful; + * + * Bug ID 4944758 - selectTextRange method needed + */ + typedef struct SelectTextRangePackageTag { + long vmID; + AccessibleContext accessibleContext; + jint startIndex; + jint endIndex; + } SelectTextRangePackage; + + /** + * Gets the number of contiguous characters with the same attributes. + * + * Bug ID 4944761 - getTextAttributes between two indices method needed + */ + typedef struct GetTextAttributesInRangePackageTag { + long vmID; + AccessibleContext accessibleContext; + jint startIndex; // start index (inclusive) + jint endIndex; // end index (inclusive) + AccessibleTextAttributesInfo attributes; // character attributes to match + short rLength; // number of contiguous characters with matching attributes + } GetTextAttributesInRangePackage; + +#define MAX_VISIBLE_CHILDREN 256 + + // visible children information + typedef struct VisibleChildenInfoTag { + int returnedChildrenCount; // number of children returned + AccessibleContext children[MAX_VISIBLE_CHILDREN]; // the visible children + } VisibleChildrenInfo; + + // struct for sending a message to get the number of visible children + typedef struct GetVisibleChildrenCountPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // AccessibleContext of parent component + jint rChildrenCount; // visible children count return value + } GetVisibleChildrenCountPackage; + + // struct for sending a message to get the hypertext for an AccessibleContext + // starting at a specified index in the document + typedef struct GetVisibleChildrenPackageTag { + long vmID; // the virtual machine ID + JOBJECT64 accessibleContext; // AccessibleContext of parent component + jint startIndex; // start index for retrieving children + VisibleChildrenInfo rVisibleChildrenInfo; // returned info + BOOL rSuccess; // whether call succeeded + } GetVisibleChildrenPackage; + + /** + * Set the caret to a text position. Returns whether successful; + * + * Bug ID 4944770 - setCaretPosition method needed + */ + typedef struct SetCaretPositionPackageTag { + long vmID; + AccessibleContext accessibleContext; + jint position; + } SetCaretPositionPackage; + + + /** + ****************************************************** + * Wrapping up all of the packages + ****************************************************** + */ + + /** + * What is the type of this package + */ + typedef enum PackageType { + + cMemoryMappedFileCreatedPackage = 0x11000, + + // many of these will go away... + cJavaVMCreatedPackage = 0x10000, + cJavaVMDestroyedPackage, + cWindowsATCreatedPackage, + cWindowsATDestroyedPackage, + cJavaVMPresentNotificationPackage, + cWindowsATPresentNotificationPackage, + + cReleaseJavaObjectPackage = 1, + cGetAccessBridgeVersionPackage = 2, + + cGetAccessibleContextFromHWNDPackage = 0x10, + cIsJavaWindowPackage, + cGetHWNDFromAccessibleContextPackage, + + cGetAccessibleContextAtPackage = 0x100, + cGetAccessibleContextWithFocusPackage, + cGetAccessibleContextInfoPackage, + cGetAccessibleChildFromContextPackage, + cGetAccessibleParentFromContextPackage, + cIsSameObjectPackage, + + cGetAccessibleTextInfoPackage = 0x200, + cGetAccessibleTextItemsPackage, + cGetAccessibleTextSelectionInfoPackage, + cGetAccessibleTextAttributeInfoPackage, + cGetAccessibleTextRectInfoPackage, + cGetAccessibleTextLineBoundsPackage, + cGetAccessibleTextRangePackage, + + cGetCurrentAccessibleValueFromContextPackage = 0x300, + cGetMaximumAccessibleValueFromContextPackage, + cGetMinimumAccessibleValueFromContextPackage, + + cAddAccessibleSelectionFromContextPackage = 0x400, + cClearAccessibleSelectionFromContextPackage, + cGetAccessibleSelectionFromContextPackage, + cGetAccessibleSelectionCountFromContextPackage, + cIsAccessibleChildSelectedFromContextPackage, + cRemoveAccessibleSelectionFromContextPackage, + cSelectAllAccessibleSelectionFromContextPackage, + + cAddJavaEventNotificationPackage = 0x900, + cRemoveJavaEventNotificationPackage, + cAddAccessibilityEventNotificationPackage, + cRemoveAccessibilityEventNotificationPackage, + + cPropertyChangePackage = 0x1000, + + cJavaShutdownPackage = 0x1010, + cFocusGainedPackage, + cFocusLostPackage, + + cCaretUpdatePackage = 0x1020, + + cMouseClickedPackage = 0x1030, + cMouseEnteredPackage, + cMouseExitedPackage, + cMousePressedPackage, + cMouseReleasedPackage, + + cMenuCanceledPackage = 0x1040, + cMenuDeselectedPackage, + cMenuSelectedPackage, + cPopupMenuCanceledPackage, + cPopupMenuWillBecomeInvisiblePackage, + cPopupMenuWillBecomeVisiblePackage, + + cPropertyCaretChangePackage = 0x1100, + cPropertyDescriptionChangePackage, + cPropertyNameChangePackage, + cPropertySelectionChangePackage, + cPropertyStateChangePackage, + cPropertyTextChangePackage, + cPropertyValueChangePackage, + cPropertyVisibleDataChangePackage, + cPropertyChildChangePackage, + cPropertyActiveDescendentChangePackage, + + + // AccessibleTable + cGetAccessibleTableInfoPackage = 0x1200, + cGetAccessibleTableCellInfoPackage, + + cGetAccessibleTableRowHeaderPackage, + cGetAccessibleTableColumnHeaderPackage, + + cGetAccessibleTableRowDescriptionPackage, + cGetAccessibleTableColumnDescriptionPackage, + + cGetAccessibleTableRowSelectionCountPackage, + cIsAccessibleTableRowSelectedPackage, + cGetAccessibleTableRowSelectionsPackage, + + cGetAccessibleTableColumnSelectionCountPackage, + cIsAccessibleTableColumnSelectedPackage, + cGetAccessibleTableColumnSelectionsPackage, + + cGetAccessibleTableRowPackage, + cGetAccessibleTableColumnPackage, + cGetAccessibleTableIndexPackage, + + cPropertyTableModelChangePackage, + + + // AccessibleRelationSet + cGetAccessibleRelationSetPackage = 0x1300, + + // AccessibleHypertext + cGetAccessibleHypertextPackage = 0x1400, + cActivateAccessibleHyperlinkPackage, + cGetAccessibleHyperlinkCountPackage, + cGetAccessibleHypertextExtPackage, + cGetAccessibleHypertextLinkIndexPackage, + cGetAccessibleHyperlinkPackage, + + // Accessible KeyBinding, Icon and Action + cGetAccessibleKeyBindingsPackage = 0x1500, + cGetAccessibleIconsPackage, + cGetAccessibleActionsPackage, + cDoAccessibleActionsPackage, + + // Utility methods + cSetTextContentsPackage = 0x1600, + cGetParentWithRolePackage, + cGetTopLevelObjectPackage, + cGetParentWithRoleElseRootPackage, + cGetObjectDepthPackage, + cGetActiveDescendentPackage, + + // Additional methods for Teton + cGetVirtualAccessibleNamePackage = 0x1700, + cRequestFocusPackage, + cSelectTextRangePackage, + cGetTextAttributesInRangePackage, + cGetSameTextAttributesInRangePackage, + cGetVisibleChildrenCountPackage, + cGetVisibleChildrenPackage, + cSetCaretPositionPackage, + cGetCaretLocationPackage + + + } PackageType; + + + /** + * Union of all package contents + */ + typedef union AllPackagesTag { + + // Initial Rendezvous packages + MemoryMappedFileCreatedPackage memoryMappedFileCreatedPackage; + + JavaVMCreatedPackage javaVMCreatedPackage; + JavaVMDestroyedPackage javaVMDestroyedPackage; + WindowsATCreatedPackage windowsATCreatedPackage; + WindowsATDestroyedPackage windowsATDestroyedPackage; + JavaVMPresentNotificationPackage javaVMPresentNotificationPackage; + WindowsATPresentNotificationPackage windowsATPresentNotificationPackage; + + // Core packages + ReleaseJavaObjectPackage releaseJavaObject; + GetAccessBridgeVersionPackage getAccessBridgeVersion; + + // Window packages + GetAccessibleContextFromHWNDPackage getAccessibleContextFromHWND; + GetHWNDFromAccessibleContextPackage getHWNDFromAccessibleContext; + + // AccessibleContext packages + GetAccessibleContextAtPackage getAccessibleContextAt; + GetAccessibleContextWithFocusPackage getAccessibleContextWithFocus; + GetAccessibleContextInfoPackage getAccessibleContextInfo; + GetAccessibleChildFromContextPackage getAccessibleChildFromContext; + GetAccessibleParentFromContextPackage getAccessibleParentFromContext; + + // AccessibleText packages + GetAccessibleTextInfoPackage getAccessibleTextInfo; + GetAccessibleTextItemsPackage getAccessibleTextItems; + GetAccessibleTextSelectionInfoPackage getAccessibleTextSelectionInfo; + GetAccessibleTextAttributeInfoPackage getAccessibleTextAttributeInfo; + GetAccessibleTextRectInfoPackage getAccessibleTextRectInfo; + GetAccessibleTextLineBoundsPackage getAccessibleTextLineBounds; + GetAccessibleTextRangePackage getAccessibleTextRange; + + // AccessibleValue packages + GetCurrentAccessibleValueFromContextPackage getCurrentAccessibleValueFromContext; + GetMaximumAccessibleValueFromContextPackage getMaximumAccessibleValueFromContext; + GetMinimumAccessibleValueFromContextPackage getMinimumAccessibleValueFromContext; + + // AccessibleSelection packages + AddAccessibleSelectionFromContextPackage addAccessibleSelectionFromContext; + ClearAccessibleSelectionFromContextPackage clearAccessibleSelectionFromContext; + GetAccessibleSelectionFromContextPackage getAccessibleSelectionFromContext; + GetAccessibleSelectionCountFromContextPackage getAccessibleSelectionCountFromContext; + IsAccessibleChildSelectedFromContextPackage isAccessibleChildSelectedFromContext; + RemoveAccessibleSelectionFromContextPackage removeAccessibleSelectionFromContext; + SelectAllAccessibleSelectionFromContextPackage selectAllAccessibleSelectionFromContext; + + // Event Notification Registration packages + AddJavaEventNotificationPackage addJavaEventNotification; + RemoveJavaEventNotificationPackage removeJavaEventNotification; + AddAccessibilityEventNotificationPackage addAccessibilityEventNotification; + RemoveAccessibilityEventNotificationPackage removeAccessibilityEventNotification; + + // Event contents packages + // PropertyChangePackage propertyChange; + PropertyCaretChangePackage propertyCaretChangePackage; + PropertyDescriptionChangePackage propertyDescriptionChangePackage; + PropertyNameChangePackage propertyNameChangePackage; + PropertySelectionChangePackage propertySelectionChangePackage; + PropertyStateChangePackage propertyStateChangePackage; + PropertyTextChangePackage propertyTextChangePackage; + PropertyValueChangePackage propertyValueChangePackage; + PropertyVisibleDataChangePackage propertyVisibleDataChangePackage; + PropertyChildChangePackage propertyChildChangePackage; + PropertyActiveDescendentChangePackage propertyActiveDescendentChangePackage; + + PropertyTableModelChangePackage propertyTableModelChangePackage; + + JavaShutdownPackage JavaShutdown; + FocusGainedPackage focusGained; + FocusLostPackage focusLost; + + CaretUpdatePackage caretUpdate; + + MouseClickedPackage mouseClicked; + MouseEnteredPackage mouseEntered; + MouseExitedPackage mouseExited; + MousePressedPackage mousePressed; + MouseReleasedPackage mouseReleased; + + MenuCanceledPackage menuCanceled; + MenuDeselectedPackage menuDeselected; + MenuSelectedPackage menuSelected; + PopupMenuCanceledPackage popupMenuCanceled; + PopupMenuWillBecomeInvisiblePackage popupMenuWillBecomeInvisible; + PopupMenuWillBecomeVisiblePackage popupMenuWillBecomeVisible; + + // AccessibleRelationSet + GetAccessibleRelationSetPackage getAccessibleRelationSet; + + // AccessibleHypertext + GetAccessibleHypertextPackage _getAccessibleHypertext; + ActivateAccessibleHyperlinkPackage _activateAccessibleHyperlink; + GetAccessibleHyperlinkCountPackage _getAccessibleHyperlinkCount; + GetAccessibleHypertextExtPackage _getAccessibleHypertextExt; + GetAccessibleHypertextLinkIndexPackage _getAccessibleHypertextLinkIndex; + GetAccessibleHyperlinkPackage _getAccessibleHyperlink; + + // Accessible KeyBinding, Icon and Action + GetAccessibleKeyBindingsPackage getAccessibleKeyBindings; + GetAccessibleIconsPackage getAccessibleIcons; + GetAccessibleActionsPackage getAccessibleActions; + DoAccessibleActionsPackage doAccessibleActions; + + // utility methods + SetTextContentsPackage _setTextContents; + GetParentWithRolePackage _getParentWithRole; + GetTopLevelObjectPackage _getTopLevelObject; + GetParentWithRoleElseRootPackage _getParentWithRoleElseRoot; + GetObjectDepthPackage _getObjectDepth; + GetActiveDescendentPackage _getActiveDescendent; + + // Additional methods for Teton + GetVirtualAccessibleNamePackage _getVirtualAccessibleName; + RequestFocusPackage _requestFocus; + SelectTextRangePackage _selectTextRange; + GetTextAttributesInRangePackage _getTextAttributesInRange; + GetVisibleChildrenCountPackage _getVisibleChildrenCount; + GetVisibleChildrenPackage _getVisibleChildren; + SetCaretPositionPackage _setCaretPosition; + + } AllPackages; + + + /** + * Union of all Java-initiated package contents + */ + typedef union JavaInitiatedPackagesTag { + + // Initial Rendezvous packages + JavaVMCreatedPackage javaVMCreatedPackage; + JavaVMDestroyedPackage javaVMDestroyedPackage; + JavaVMPresentNotificationPackage javaVMPresentNotificationPackage; + + // Event contents packages + PropertyCaretChangePackage propertyCaretChangePackage; + PropertyDescriptionChangePackage propertyDescriptionChangePackage; + PropertyNameChangePackage propertyNameChangePackage; + PropertySelectionChangePackage propertySelectionChangePackage; + PropertyStateChangePackage propertyStateChangePackage; + PropertyTextChangePackage propertyTextChangePackage; + PropertyValueChangePackage propertyValueChangePackage; + PropertyVisibleDataChangePackage propertyVisibleDataChangePackage; + PropertyChildChangePackage propertyChildChangePackage; + PropertyActiveDescendentChangePackage propertyActiveDescendentChangePackage; + + PropertyTableModelChangePackage propertyTableModelChangePackage; + + JavaShutdownPackage JavaShutdown; + FocusGainedPackage focusGained; + FocusLostPackage focusLost; + + CaretUpdatePackage caretUpdate; + + MouseClickedPackage mouseClicked; + MouseEnteredPackage mouseEntered; + MouseExitedPackage mouseExited; + MousePressedPackage mousePressed; + MouseReleasedPackage mouseReleased; + + MenuCanceledPackage menuCanceled; + MenuDeselectedPackage menuDeselected; + MenuSelectedPackage menuSelected; + PopupMenuCanceledPackage popupMenuCanceled; + PopupMenuWillBecomeInvisiblePackage popupMenuWillBecomeInvisible; + PopupMenuWillBecomeVisiblePackage popupMenuWillBecomeVisible; + + } JavaInitiatedPackages; + + + /** + * Union of all Windows-initiated package contents + */ + typedef union WindowsInitiatedPackagesTag { + + // Initial Rendezvous packages + MemoryMappedFileCreatedPackage memoryMappedFileCreatedPackage; + + WindowsATCreatedPackage windowsATCreatedPackage; + WindowsATDestroyedPackage windowsATDestroyedPackage; + WindowsATPresentNotificationPackage windowsATPresentNotificationPackage; + + // Core packages + ReleaseJavaObjectPackage releaseJavaObject; + GetAccessBridgeVersionPackage getAccessBridgeVersion; + + // Window packages + GetAccessibleContextFromHWNDPackage getAccessibleContextFromHWND; + GetHWNDFromAccessibleContextPackage getHWNDFromAccessibleContext; + + // AccessibleContext packages + GetAccessibleContextAtPackage getAccessibleContextAt; + GetAccessibleContextWithFocusPackage getAccessibleContextWithFocus; + GetAccessibleContextInfoPackage getAccessibleContextInfo; + GetAccessibleChildFromContextPackage getAccessibleChildFromContext; + GetAccessibleParentFromContextPackage getAccessibleParentFromContext; + + // AccessibleText packages + GetAccessibleTextInfoPackage getAccessibleTextInfo; + GetAccessibleTextItemsPackage getAccessibleTextItems; + GetAccessibleTextSelectionInfoPackage getAccessibleTextSelectionInfo; + GetAccessibleTextAttributeInfoPackage getAccessibleTextAttributeInfo; + GetAccessibleTextRectInfoPackage getAccessibleTextRectInfo; + GetAccessibleTextLineBoundsPackage getAccessibleTextLineBounds; + GetAccessibleTextRangePackage getAccessibleTextRange; + + // AccessibleValue packages + GetCurrentAccessibleValueFromContextPackage getCurrentAccessibleValueFromContext; + GetMaximumAccessibleValueFromContextPackage getMaximumAccessibleValueFromContext; + GetMinimumAccessibleValueFromContextPackage getMinimumAccessibleValueFromContext; + + // AccessibleSelection packages + AddAccessibleSelectionFromContextPackage addAccessibleSelectionFromContext; + ClearAccessibleSelectionFromContextPackage clearAccessibleSelectionFromContext; + GetAccessibleSelectionFromContextPackage getAccessibleSelectionFromContext; + GetAccessibleSelectionCountFromContextPackage getAccessibleSelectionCountFromContext; + IsAccessibleChildSelectedFromContextPackage isAccessibleChildSelectedFromContext; + RemoveAccessibleSelectionFromContextPackage removeAccessibleSelectionFromContext; + SelectAllAccessibleSelectionFromContextPackage selectAllAccessibleSelectionFromContext; + + // Event Notification Registration packages + AddJavaEventNotificationPackage addJavaEventNotification; + RemoveJavaEventNotificationPackage removeJavaEventNotification; + AddAccessibilityEventNotificationPackage addAccessibilityEventNotification; + RemoveAccessibilityEventNotificationPackage removeAccessibilityEventNotification; + + // AccessibleTable + GetAccessibleTableInfoPackage _getAccessibleTableInfo; + GetAccessibleTableCellInfoPackage _getAccessibleTableCellInfo; + + GetAccessibleTableRowHeaderPackage _getAccessibleTableRowHeader; + GetAccessibleTableColumnHeaderPackage _getAccessibleTableColumnHeader; + + GetAccessibleTableRowDescriptionPackage _getAccessibleTableRowDescription; + GetAccessibleTableColumnDescriptionPackage _getAccessibleTableColumnDescription; + + GetAccessibleTableRowSelectionCountPackage _getAccessibleTableRowSelectionCount; + IsAccessibleTableRowSelectedPackage _isAccessibleTableRowSelected; + GetAccessibleTableRowSelectionsPackage _getAccessibleTableRowSelections; + + GetAccessibleTableColumnSelectionCountPackage _getAccessibleTableColumnSelectionCount; + IsAccessibleTableColumnSelectedPackage _isAccessibleTableColumnSelected; + GetAccessibleTableColumnSelectionsPackage _getAccessibleTableColumnSelections; + + GetAccessibleTableRowPackage _getAccessibleTableRow; + GetAccessibleTableColumnPackage _getAccessibleTableColumn; + GetAccessibleTableIndexPackage _getAccessibleTableIndex; + + // AccessibleRelationSet + GetAccessibleRelationSetPackage _getAccessibleRelationSet; + + // Accessible KeyBindings, Icons and Actions + GetAccessibleKeyBindingsPackage _getAccessibleKeyBindings; + GetAccessibleIconsPackage _getAccessibleIcons; + GetAccessibleActionsPackage _getAccessibleActions; + DoAccessibleActionsPackage _doAccessibleActions; + + + IsSameObjectPackage _isSameObject; + + // utility methods + SetTextContentsPackage _setTextContents; + GetParentWithRolePackage _getParentWithRole; + GetTopLevelObjectPackage _getTopLevelObject; + GetParentWithRoleElseRootPackage _getParentWithRoleElseRoot; + GetObjectDepthPackage _getObjectDepth; + GetActiveDescendentPackage _getActiveDescendent; + + // Additional methods for Teton + GetVirtualAccessibleNamePackage _getVirtualAccessibleName; + RequestFocusPackage _requestFocus; + SelectTextRangePackage _selectTextRange; + GetTextAttributesInRangePackage _getTextAttributesInRange; + GetVisibleChildrenCountPackage _getVisibleChildrenCount; + GetVisibleChildrenPackage _getVisibleChildren; + SetCaretPositionPackage _setCaretPosition; + + + } WindowsInitiatedPackages; + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/arthas-vmtool/src/main/native/head/windows/jawt_md.h b/arthas-vmtool/src/main/native/head/windows/jawt_md.h new file mode 100755 index 000000000..66e7256a2 --- /dev/null +++ b/arthas-vmtool/src/main/native/head/windows/jawt_md.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JAWT_MD_H_ +#define _JAVASOFT_JAWT_MD_H_ + +#include +#include "jawt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Win32-specific declarations for AWT native interface. + * See notes in jawt.h for an example of use. + */ +typedef struct jawt_Win32DrawingSurfaceInfo { + /* Native window, DDB, or DIB handle */ + union { + HWND hwnd; + HBITMAP hbitmap; + void* pbits; + }; + /* + * This HDC should always be used instead of the HDC returned from + * BeginPaint() or any calls to GetDC(). + */ + HDC hdc; + HPALETTE hpalette; +} JAWT_Win32DrawingSurfaceInfo; + +#ifdef __cplusplus +} +#endif + +#endif /* !_JAVASOFT_JAWT_MD_H_ */ diff --git a/arthas-vmtool/src/main/native/head/windows/jni_md.h b/arthas-vmtool/src/main/native/head/windows/jni_md.h new file mode 100755 index 000000000..38080013b --- /dev/null +++ b/arthas-vmtool/src/main/native/head/windows/jni_md.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved. + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + +#ifndef _JAVASOFT_JNI_MD_H_ +#define _JAVASOFT_JNI_MD_H_ + +#define JNIEXPORT __declspec(dllexport) +#define JNIIMPORT __declspec(dllimport) +#define JNICALL __stdcall + +typedef long jint; +typedef __int64 jlong; +typedef signed char jbyte; + +#endif /* !_JAVASOFT_JNI_MD_H_ */ diff --git a/arthas-vmtool/src/main/native/src/jni-library.cpp b/arthas-vmtool/src/main/native/src/jni-library.cpp new file mode 100644 index 000000000..c0bbc33ad --- /dev/null +++ b/arthas-vmtool/src/main/native/src/jni-library.cpp @@ -0,0 +1,207 @@ +#include +#include +#include +#include +#include "arthas_VmTool.h" // under target/native/javah/ + + +static jvmtiEnv *jvmti; +static jlong tagCounter = 0; + +struct LimitCounter { + jint currentCounter; + jint limitValue; + + void init(jint limit) { + currentCounter = 0; + limitValue = limit; + } + + void countDown() { + currentCounter++; + } + + bool allow() { + if (limitValue < 0) { + return true; + } + return limitValue > currentCounter; + } +}; + +// 每次 IterateOverInstancesOfClass 调用前需要先 init +static LimitCounter limitCounter = {0, 0}; + +extern "C" +int init_agent(JavaVM *vm, void *reserved) { + jint rc; + /* Get JVMTI environment */ + rc = vm->GetEnv((void **)&jvmti, JVMTI_VERSION_1_2); + if (rc != JNI_OK) { + fprintf(stderr, "ERROR: arthas vmtool Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc); + return -1; + } + + jvmtiCapabilities capabilities = {0}; + capabilities.can_tag_objects = 1; + jvmtiError error = jvmti->AddCapabilities(&capabilities); + if (error) { + fprintf(stderr, "ERROR: arthas vmtool JVMTI AddCapabilities failed!%u\n", error); + return JNI_FALSE; + } + + return JNI_OK; +} + +extern "C" JNIEXPORT jint JNICALL +Agent_OnLoad(JavaVM *vm, char *options, void *reserved) { + return init_agent(vm, reserved); +} + +extern "C" JNIEXPORT jint JNICALL +Agent_OnAttach(JavaVM* vm, char* options, void* reserved) { + return init_agent(vm, reserved); +} + +extern "C" JNIEXPORT jint JNICALL +JNI_OnLoad(JavaVM* vm, void* reserved) { + init_agent(vm, reserved); + return JNI_VERSION_1_6; +} + +extern "C" +JNIEXPORT void JNICALL +Java_arthas_VmTool_forceGc0(JNIEnv *env, jclass thisClass) { + jvmti->ForceGarbageCollection(); +} + +extern "C" +jlong getTag() { + return ++tagCounter; +} + +extern "C" +jvmtiIterationControl JNICALL +HeapObjectCallback(jlong class_tag, jlong size, jlong *tag_ptr, void *user_data) { + jlong *data = static_cast(user_data); + *tag_ptr = *data; + + limitCounter.countDown(); + if (limitCounter.allow()) { + return JVMTI_ITERATION_CONTINUE; + }else { + return JVMTI_ITERATION_ABORT; + } +} + +extern "C" +JNIEXPORT jobjectArray JNICALL +Java_arthas_VmTool_getInstances0(JNIEnv *env, jclass thisClass, jclass klass, jint limit) { + jlong tag = getTag(); + limitCounter.init(limit); + jvmtiError error = jvmti->IterateOverInstancesOfClass(klass, JVMTI_HEAP_OBJECT_EITHER, + HeapObjectCallback, &tag); + if (error) { + printf("ERROR: JVMTI IterateOverInstancesOfClass failed!%u\n", error); + return NULL; + } + + jint count = 0; + jobject *instances; + error = jvmti->GetObjectsWithTags(1, &tag, &count, &instances, NULL); + if (error) { + printf("ERROR: JVMTI GetObjectsWithTags failed!%u\n", error); + return NULL; + } + + jobjectArray array = env->NewObjectArray(count, klass, NULL); + //添加元素到数组 + for (int i = 0; i < count; i++) { + env->SetObjectArrayElement(array, i, instances[i]); + } + jvmti->Deallocate(reinterpret_cast(instances)); + return array; +} + +extern "C" +JNIEXPORT jlong JNICALL +Java_arthas_VmTool_sumInstanceSize0(JNIEnv *env, jclass thisClass, jclass klass) { + jlong tag = getTag(); + limitCounter.init(-1); + jvmtiError error = jvmti->IterateOverInstancesOfClass(klass, JVMTI_HEAP_OBJECT_EITHER, + HeapObjectCallback, &tag); + if (error) { + printf("ERROR: JVMTI IterateOverInstancesOfClass failed!%u\n", error); + return -1; + } + + jint count = 0; + jobject *instances; + error = jvmti->GetObjectsWithTags(1, &tag, &count, &instances, NULL); + if (error) { + printf("ERROR: JVMTI GetObjectsWithTags failed!%u\n", error); + return -1; + } + + jlong sum = 0; + for (int i = 0; i < count; i++) { + jlong size = 0; + jvmti->GetObjectSize(instances[i], &size); + sum = sum + size; + } + jvmti->Deallocate(reinterpret_cast(instances)); + return sum; +} + +extern "C" +JNIEXPORT jlong JNICALL Java_arthas_VmTool_getInstanceSize0 + (JNIEnv *env, jclass thisClass, jobject instance) { + jlong size = -1; + jvmtiError error = jvmti->GetObjectSize(instance, &size); + if (error) { + printf("ERROR: JVMTI GetObjectSize failed!%u\n", error); + } + return size; +} + +extern "C" +JNIEXPORT jlong JNICALL +Java_arthas_VmTool_countInstances0(JNIEnv *env, jclass thisClass, jclass klass) { + jlong tag = getTag(); + limitCounter.init(-1); + jvmtiError error = jvmti->IterateOverInstancesOfClass(klass, JVMTI_HEAP_OBJECT_EITHER, + HeapObjectCallback, &tag); + if (error) { + printf("ERROR: JVMTI IterateOverInstancesOfClass failed!%u\n", error); + return -1; + } + + jint count = 0; + error = jvmti->GetObjectsWithTags(1, &tag, &count, NULL, NULL); + if (error) { + printf("ERROR: JVMTI GetObjectsWithTags failed!%u\n", error); + return -1; + } + return count; +} + +extern "C" +JNIEXPORT jobjectArray JNICALL Java_arthas_VmTool_getAllLoadedClasses0 + (JNIEnv *env, jclass thisClass, jclass kclass) { + jclass *classes; + jint count = 0; + + jvmtiError error = jvmti->GetLoadedClasses(&count, &classes); + if (error) { + printf("ERROR: JVMTI GetLoadedClasses failed!\n"); + return NULL; + } + + jobjectArray array = env->NewObjectArray(count, kclass, NULL); + //添加元素到数组 + for (int i = 0; i < count; i++) { + env->SetObjectArrayElement(array, i, classes[i]); + } + jvmti->Deallocate(reinterpret_cast(classes)); + return array; +} \ No newline at end of file diff --git a/arthas-vmtool/src/test/java/arthas/VmToolTest.java b/arthas-vmtool/src/test/java/arthas/VmToolTest.java new file mode 100644 index 000000000..8a573f7e1 --- /dev/null +++ b/arthas-vmtool/src/test/java/arthas/VmToolTest.java @@ -0,0 +1,185 @@ +package arthas; + +import java.io.File; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicLong; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import com.taobao.arthas.common.VmToolUtils; + +/** + * 以下本地测试的jvm参数均为:-Xms128m -Xmx128m + */ +public class VmToolTest { + private VmTool initVmTool() { + File path = new File(VmTool.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile(); + + String libPath = new File(path, VmToolUtils.detectLibName()).getAbsolutePath(); + return VmTool.getInstance(libPath); + } + + /** + * macbook上运行结果如下 + * allLoadedClasses->1050 + * arthas.VmTool@5bb21b69 arthas.VmTool@6b9651f3 + * before instances->[arthas.VmTool@5bb21b69, arthas.VmTool@6b9651f3] + * size->16 + * count->2 + * sum size->32 + * null null + * after instances->[] + */ + @Test + public void testIsSnapshot() { + try { + VmTool vmtool = initVmTool(); + //调用native方法,获取已加载的类,不包括小类型(如int) + Class[] allLoadedClasses = vmtool.getAllLoadedClasses(); + System.out.println("allLoadedClasses->" + allLoadedClasses.length); + + //通过下面的例子,可以看到getInstances(Class klass)拿到的是当前存活的所有对象 + WeakReference weakReference1 = new WeakReference(new VmToolTest()); + WeakReference weakReference2 = new WeakReference(new VmToolTest()); + System.out.println(weakReference1.get() + " " + weakReference2.get()); + VmTool[] beforeInstances = vmtool.getInstances(VmTool.class); + System.out.println("before instances->" + beforeInstances); + System.out.println("size->" + vmtool.getInstanceSize(weakReference1.get())); + System.out.println("count->" + vmtool.countInstances(VmTool.class)); + System.out.println("sum size->" + vmtool.sumInstanceSize(VmTool.class)); + beforeInstances = null; + + vmtool.forceGc(); + Thread.sleep(100); + System.out.println(weakReference1.get() + " " + weakReference2.get()); + VmTool[] afterInstances = vmtool.getInstances(VmTool.class); + System.out.println("after instances->" + afterInstances); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testGetInstancesMemoryLeak() { + //这里睡20s是为了方便用jprofiler连接上进程 +// try { +// Thread.sleep(20000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + VmTool vmtool = initVmTool(); + final AtomicLong totalTime = new AtomicLong(); + //本地测试请改成200000 + for (int i = 1; i <= 2; i++) { + long start = System.currentTimeMillis(); + WeakReference reference = new WeakReference(vmtool.getInstances(Object.class)); + Object[] instances = reference.get(); + long cost = System.currentTimeMillis() - start; + totalTime.addAndGet(cost); + System.out.println(i + " instance size:" + (instances == null ? 0 : instances.length) + ", cost " + cost + "ms avgCost " + totalTime.doubleValue() / i + "ms"); + instances = null; + vmtool.forceGc(); + } + } + + @Test + public void testSumInstancesMemoryLeak() { + //这里睡20s是为了方便用jprofiler连接上进程 +// try { +// Thread.sleep(20000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + VmTool vmtool = initVmTool(); + final AtomicLong totalTime = new AtomicLong(); + //本地测试请改成200000 + for (int i = 1; i <= 2; i++) { + long start = System.currentTimeMillis(); + long sum = vmtool.sumInstanceSize(Object.class); + long cost = System.currentTimeMillis() - start; + totalTime.addAndGet(cost); + System.out.println(i + " sum:" + sum + ", cost " + cost + "ms avgCost " + totalTime.doubleValue() / i + "ms"); + } + } + + @Test + public void testCountInstancesMemoryLeak() { + //这里睡20s是为了方便用jprofiler连接上进程 +// try { +// Thread.sleep(20000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + VmTool vmtool = initVmTool(); + final AtomicLong totalTime = new AtomicLong(); + //本地测试请改成200000 + for (int i = 1; i <= 2; i++) { + long start = System.currentTimeMillis(); + long count = vmtool.countInstances(Object.class); + long cost = System.currentTimeMillis() - start; + totalTime.addAndGet(cost); + System.out.println(i + " count:" + count + ", cost " + cost + "ms avgCost " + totalTime.doubleValue() / i + "ms"); + } + } + + @Test + public void testGetAllLoadedClassesMemoryLeak() { + //这里睡20s是为了方便用jprofiler连接上进程 +// try { +// Thread.sleep(20000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + VmTool vmtool = initVmTool(); + final AtomicLong totalTime = new AtomicLong(); + //本地测试请改成200000 + for (int i = 1; i <= 2; i++) { + long start = System.currentTimeMillis(); + Class[] allLoadedClasses = vmtool.getAllLoadedClasses(); + long cost = System.currentTimeMillis() - start; + totalTime.addAndGet(cost); + System.out.println(i + " class size:" + allLoadedClasses.length + ", cost " + cost + "ms avgCost " + totalTime.doubleValue() / i + "ms"); + allLoadedClasses = null; + } + } + + class LimitTest { + } + + @Test + public void test_getInstances_lmiit() { + VmTool vmtool = initVmTool(); + + ArrayList list = new ArrayList(); + for (int i = 0; i < 10; ++i) { + list.add(new LimitTest()); + } + LimitTest[] instances = vmtool.getInstances(LimitTest.class, 5); + Assertions.assertThat(instances).hasSize(5); + LimitTest[] instances2 = vmtool.getInstances(LimitTest.class, -1); + Assertions.assertThat(instances2).hasSize(10); + LimitTest[] instances3 = vmtool.getInstances(LimitTest.class, 1); + Assertions.assertThat(instances3).hasSize(1); + } + + interface III { + } + + class AAA implements III { + } + + @Test + public void test_getInstances_interface() { + AAA aaa = new AAA(); + VmTool vmtool = initVmTool(); + III[] interfaceInstances = vmtool.getInstances(III.class); + Assertions.assertThat(interfaceInstances.length).isEqualTo(1); + + AAA[] ObjectInstances = vmtool.getInstances(AAA.class); + Assertions.assertThat(ObjectInstances.length).isEqualTo(1); + + Assertions.assertThat(interfaceInstances[0]).isEqualTo(ObjectInstances[0]); + } +} diff --git a/as-package.sh b/as-package.sh index 6a9bbfd24..840798dfc 100755 --- a/as-package.sh +++ b/as-package.sh @@ -33,7 +33,7 @@ exit_on_err() } # maven package the arthas -"$DIR/mvnw" clean package -T 2C -Dmaven.test.skip=true -DskipTests=true -Dmaven.javadoc.skip=true -f $DIR/pom.xml \ +"$DIR/mvnw" clean package -Dmaven.test.skip=true -DskipTests=true -Dmaven.javadoc.skip=true -f $DIR/pom.xml \ || exit_on_err 1 "package arthas failed." rm -r "$DIR/core/src/main/resources/com/taobao/arthas/core/res/version" diff --git a/async-profiler/libasyncProfiler-linux-aarch64.so b/async-profiler/libasyncProfiler-linux-aarch64.so new file mode 100755 index 000000000..9c0998521 Binary files /dev/null and b/async-profiler/libasyncProfiler-linux-aarch64.so differ diff --git a/async-profiler/libasyncProfiler-linux-arm.so b/async-profiler/libasyncProfiler-linux-arm.so index 6606c411a..330a5552e 100755 Binary files a/async-profiler/libasyncProfiler-linux-arm.so and b/async-profiler/libasyncProfiler-linux-arm.so differ diff --git a/async-profiler/libasyncProfiler-linux-x64.so b/async-profiler/libasyncProfiler-linux-x64.so index ff5912bce..4e4067215 100755 Binary files a/async-profiler/libasyncProfiler-linux-x64.so and b/async-profiler/libasyncProfiler-linux-x64.so differ diff --git a/async-profiler/libasyncProfiler-mac-x64.so b/async-profiler/libasyncProfiler-mac-x64.so index b5f85cb39..898bfd50b 100755 Binary files a/async-profiler/libasyncProfiler-mac-x64.so and b/async-profiler/libasyncProfiler-mac-x64.so differ diff --git a/bin/as.bat b/bin/as.bat index b40f3d734..18bd402e7 100755 --- a/bin/as.bat +++ b/bin/as.bat @@ -24,6 +24,7 @@ if ["%~1"]==[""] ( goto exit_bat ) +set JAVA_TOOL_OPTIONS set AGENT_JAR=%BASEDIR%\arthas-agent.jar set CORE_JAR=%BASEDIR%\arthas-core.jar diff --git a/bin/as.sh b/bin/as.sh index 18f94ad23..6f2e26d4c 100755 --- a/bin/as.sh +++ b/bin/as.sh @@ -8,10 +8,10 @@ # program : Arthas # author : Core Engine @ Taobao.com -# date : 2020-09-27 +# date : 2021-06-10 # current arthas script version -ARTHAS_SCRIPT_VERSION=3.4.3 +ARTHAS_SCRIPT_VERSION=3.5.2 # SYNOPSIS # rreadlink @@ -83,22 +83,27 @@ DIR=$(dirname -- "$(rreadlink "${BASH_SOURCE[0]}")") ARTHAS_HOME= # define arthas's lib -ARTHAS_LIB_DIR=${HOME}/.arthas/lib +if [ -z "${ARTHAS_LIB_DIR}" ]; then + ARTHAS_LIB_DIR=${HOME}/.arthas/lib +fi # target process id to attach TARGET_PID= -# target process id to attach -TARGET_IP="127.0.0.1" +# target process id to attach, default 127.0.0.1 +TARGET_IP= +DEFAULT_TARGET_IP="127.0.0.1" -# telnet port -TELNET_PORT="3658" +# telnet port, default 3658 +TELNET_PORT= +DEFAULT_TELNET_PORT="3658" -# http port -HTTP_PORT="8563" +# http port, default 8563 +HTTP_PORT= +DEFAULT_HTTP_PORT="8563" # telnet session timeout seconds, default 1800 -SESSION_TIMEOUT=1800 +SESSION_TIMEOUT= # use specify version USE_VERSION= @@ -139,6 +144,18 @@ AGENT_ID= # stat report url STAT_URL= +# app name +APP_NAME= + +# username +USERNAME= + +# password +PASSWORD= + +# disabledCommands +DISABLED_COMMANDS= + ############ Command Arguments ############ # if arguments contains -c/--command or -f/--batch-file, BATCH_MODE will be true @@ -147,9 +164,6 @@ BATCH_MODE=false # define arthas's temp dir TMP_DIR=/tmp -# last update arthas version -ARTHAS_VERSION= - # arthas remote url # https://arthas.aliyun.com/download/3.1.7?mirror=aliyun REMOTE_DOWNLOAD_URL="https://arthas.aliyun.com/download/PLACEHOLDER_VERSION?mirror=PLACEHOLDER_REPO" @@ -223,6 +237,7 @@ check_permission() # reset some options for env reset_for_env() { + unset JAVA_TOOL_OPTIONS # init ARTHAS' lib mkdir -p "${ARTHAS_LIB_DIR}" \ @@ -393,6 +408,9 @@ Usage: $0 [-h] [--target-ip ] [--telnet-port ] [--http-port ] [--session-timeout ] [--arthas-home ] [--tunnel-server ] [--agent-id ] [--stat-url ] + [--app-name ] + [--username ] [--password ] + [--disabled-commands ] [--use-version ] [--repo-mirror ] [--versions] [--use-http] [--attach-only] [-c ] [-f ] [-v] [pid] @@ -412,6 +430,10 @@ Options and Arguments: --debug-attach Debug attach agent --tunnel-server Remote tunnel server url --agent-id Special agent id + --app-name Special app name + --username Special username + --password Special password + --disabled-commands Disable special commands --select select target process by classname or JARfilename -c,--command Command to execute, multiple commands separated by ; @@ -425,15 +447,17 @@ EXAMPLES: ./as.sh ./as.sh --target-ip 0.0.0.0 ./as.sh --telnet-port 9999 --http-port -1 - ./as.sh --tunnel-server 'ws://192.168.10.11:7777/ws' + ./as.sh --username admin --password + ./as.sh --tunnel-server 'ws://192.168.10.11:7777/ws' --app-name demoapp ./as.sh --tunnel-server 'ws://192.168.10.11:7777/ws' --agent-id bvDOe8XbTM2pQWjF4cfw ./as.sh --stat-url 'http://192.168.10.11:8080/api/stat' ./as.sh -c 'sysprop; thread' ./as.sh -f batch.as - ./as.sh --use-version 3.4.3 + ./as.sh --use-version 3.5.2 ./as.sh --session-timeout 3600 ./as.sh --attach-only - ./as.sh --select arthas-demo + ./as.sh --disabled-commands stop,dump + ./as.sh --select math-game ./as.sh --repo-mirror aliyun --use-http WIKI: https://arthas.aliyun.com/doc @@ -461,6 +485,33 @@ find_listen_port_process() fi } +getTargetIPOrDefault() +{ + local targetIP=${DEFAULT_TARGET_IP} + if [ "${TARGET_IP}" ]; then + targetIP=${TARGET_IP} + fi + echo $targetIP +} + +getTelnetPortOrDefault() +{ + local telnetPort=${DEFAULT_TELNET_PORT} + if [ "${TELNET_PORT}" ]; then + telnetPort=${TELNET_PORT} + fi + echo $telnetPort +} + +getHttpPortOrDefault() +{ + local httpPort=${DEFAULT_HTTP_PORT} + if [ "${HTTP_PORT}" ]; then + httpPort=${HTTP_PORT} + fi + echo $httpPort +} + # Status from com.taobao.arthas.client.TelnetConsole # Execute commands timeout STATUS_EXEC_TIMEOUT=100 @@ -479,8 +530,8 @@ find_listen_port_process_by_client() "${JAVA_HOME}/bin/java" ${ARTHAS_OPTS} ${JVM_OPTS} \ -jar "${arthas_lib_dir}/arthas-client.jar" \ - ${TARGET_IP} \ - ${TELNET_PORT} \ + $(getTargetIPOrDefault) \ + $(getTelnetPortOrDefault) \ -c "session" \ --execution-timeout 2000 \ 2>&1 @@ -567,6 +618,26 @@ parse_arguments() shift # past argument shift # past value ;; + --app-name) + APP_NAME="$2" + shift # past argument + shift # past value + ;; + --username) + USERNAME="$2" + shift # past argument + shift # past value + ;; + --password) + PASSWORD="$2" + shift # past argument + shift # past value + ;; + --disabled-commands) + DISABLED_COMMANDS="$2" + shift # past argument + shift # past value + ;; --use-http) USE_HTTP=true shift # past argument @@ -637,16 +708,18 @@ parse_arguments() # check telnet port/http port local telnetPortPid local httpPortPid - if [[ $TELNET_PORT > 0 ]]; then - telnetPortPid=$(find_listen_port_process $TELNET_PORT) + local telnetPortOrDefault=$(getTelnetPortOrDefault) + local httpPortOrDefault=$(getHttpPortOrDefault) + if [[ $telnetPortOrDefault > 0 ]]; then + telnetPortPid=$(find_listen_port_process $telnetPortOrDefault) if [ $telnetPortPid ]; then - echo "[INFO] Process $telnetPortPid already using port $TELNET_PORT" + echo "[INFO] Process $telnetPortPid already using port $telnetPortOrDefault" fi fi - if [[ $HTTP_PORT > 0 ]]; then - httpPortPid=$(find_listen_port_process $HTTP_PORT) + if [[ $httpPortOrDefault > 0 ]]; then + httpPortPid=$(find_listen_port_process $httpPortOrDefault) if [ $telnetPortPid ]; then - echo "[INFO] Process $httpPortPid already using port $HTTP_PORT" + echo "[INFO] Process $httpPortPid already using port $httpPortOrDefault" fi fi @@ -668,7 +741,7 @@ parse_arguments() fi # check pid - if [ -z ${TARGET_PID} ] && [ ${BATCH_MODE} = false ]; then + if [ -z ${TARGET_PID} ]; then # interactive mode local IFS=$'\n' CANDIDATES=($(call_jps | grep -v sun.tools.jps.Jps | awk '{print $0}')) @@ -717,7 +790,7 @@ parse_arguments() exit 1 fi if [[ ($httpPortPid) && ($TARGET_PID != $httpPortPid) ]]; then - echo "Target process $TARGET_PID is not the process using port $HTTP_PORT, you will connect to an unexpected process." + echo "Target process $TARGET_PID is not the process using port $(getHttpPortOrDefault), you will connect to an unexpected process." echo "1. Try to restart as.sh, select process $httpPortPid, shutdown it first with running the 'stop' command." echo "2. Try to use different http port, for example: as.sh --telnet-port 9998 --http-port 9999" exit 1 @@ -759,14 +832,47 @@ attach_jvm() tempArgs+=("${STAT_URL}") fi + if [ "${APP_NAME}" ]; then + tempArgs+=("-app-name") + tempArgs+=("${APP_NAME}") + fi + + if [ "${USERNAME}" ]; then + tempArgs+=("-username") + tempArgs+=("${USERNAME}") + fi + + if [ "${PASSWORD}" ]; then + tempArgs+=("-password") + tempArgs+=("${PASSWORD}") + fi + + if [ "${DISABLED_COMMANDS}" ]; then + tempArgs+=("-disabled-commands") + tempArgs+=("${DISABLED_COMMANDS}") + fi + + if [ "${TARGET_IP}" ]; then + tempArgs+=("-target-ip") + tempArgs+=("${TARGET_IP}") + fi + if [ "${TELNET_PORT}" ]; then + tempArgs+=("-telnet-port") + tempArgs+=("${TELNET_PORT}") + fi + if [ "${HTTP_PORT}" ]; then + tempArgs+=("-http-port") + tempArgs+=("${HTTP_PORT}") + fi + if [ "${SESSION_TIMEOUT}" ]; then + tempArgs+=("-session-timeout") + tempArgs+=("${SESSION_TIMEOUT}") + fi + "${java_command[@]}" \ ${ARTHAS_OPTS} ${JVM_OPTS} \ -jar "${arthas_lib_dir}/arthas-core.jar" \ -pid ${TARGET_PID} \ - -target-ip ${TARGET_IP} \ - -telnet-port ${TELNET_PORT} \ - -http-port ${HTTP_PORT} \ - -session-timeout ${SESSION_TIMEOUT} \ "${tempArgs[@]}" \ -core "${arthas_lib_dir}/arthas-core.jar" \ -agent "${arthas_lib_dir}/arthas-agent.jar" @@ -811,7 +917,7 @@ sanity_check() { } port_pid_check() { - if [[ $TELNET_PORT > 0 ]]; then + if [[ $(getTelnetPortOrDefault) > 0 ]]; then local telnet_output local find_process_status # declare local var before var=$() @@ -844,15 +950,15 @@ port_pid_check() { } print_telnet_port_pid_error() { - echo "[ERROR] The telnet port $TELNET_PORT is used by process $telnetPortPid instead of target process $TARGET_PID, you will connect to an unexpected process." + echo "[ERROR] The telnet port $(getTelnetPortOrDefault) is used by process $telnetPortPid instead of target process $TARGET_PID, you will connect to an unexpected process." echo "[ERROR] 1. Try to restart as.sh, select process $telnetPortPid, shutdown it first with running the 'stop' command." - echo "[ERROR] 2. Try to stop the existing arthas instance: java -jar arthas-client.jar 127.0.0.1 $TELNET_PORT -c \"stop\"" + echo "[ERROR] 2. Try to stop the existing arthas instance: java -jar arthas-client.jar 127.0.0.1 $(getTelnetPortOrDefault) -c \"stop\"" echo "[ERROR] 3. Try to use different telnet port, for example: as.sh --telnet-port 9998 --http-port -1" } print_telnet_port_used_error() { local error_msg=$1 - echo "[ERROR] The telnet port $TELNET_PORT is used, but process $error_msg, you will connect to an unexpected process." + echo "[ERROR] The telnet port $(getTelnetPortOrDefault) is used, but process $error_msg, you will connect to an unexpected process." echo "[ERROR] Try to use different telnet port, for example: as.sh --telnet-port 9998 --http-port -1" } @@ -881,16 +987,16 @@ active_console() if [ "${COMMAND}" ] ; then "${JAVA_HOME}/bin/java" ${ARTHAS_OPTS} ${JVM_OPTS} \ -jar "${arthas_lib_dir}/arthas-client.jar" \ - ${TARGET_IP} \ - ${TELNET_PORT} \ + $(getTargetIPOrDefault) \ + $(getTelnetPortOrDefault) \ "${tempArgs[@]}" \ -c "${COMMAND}" fi if [ "${BATCH_FILE}" ] ; then "${JAVA_HOME}/bin/java" ${ARTHAS_OPTS} ${JVM_OPTS} \ -jar "${arthas_lib_dir}/arthas-client.jar" \ - ${TARGET_IP} \ - ${TELNET_PORT} \ + $(getTargetIPOrDefault) \ + $(getTelnetPortOrDefault) \ "${tempArgs[@]}" \ -f ${BATCH_FILE} fi @@ -899,12 +1005,12 @@ active_console() if [[ $(command -v telnet) == *"system32"* ]] ; then # Windows/system32/telnet.exe can not run in Cygwin/MinGw echo "It seems that current bash is under Windows. $(command -v telnet) can not run under bash." - echo "Please start cmd.exe from Windows start menu, and then run telnet ${TARGET_IP} ${TELNET_PORT} to connect to target process." - echo "Or visit http://127.0.0.1:${HTTP_PORT} to connect to target process." + echo "Please start cmd.exe from Windows start menu, and then run telnet $(getTargetIPOrDefault) $(getTelnetPortOrDefault) to connect to target process." + echo "Or visit http://127.0.0.1:$(getHttpPortOrDefault) to connect to target process." return 1 fi echo "telnet connecting to arthas server... current timestamp is `date +%s`" - telnet ${TARGET_IP} ${TELNET_PORT} + telnet $(getTargetIPOrDefault) $(getTelnetPortOrDefault) else echo "'telnet' is required." 1>&2 return 1 diff --git a/boot/pom.xml b/boot/pom.xml index f5e7629ff..5a51efa73 100644 --- a/boot/pom.xml +++ b/boot/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-boot diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index ffd9049af..fb23af229 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -1,5 +1,8 @@ package com.taobao.arthas.boot; +import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_ERROR; +import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -11,12 +14,12 @@ import java.security.CodeSource; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.InputMismatchException; import java.util.List; import java.util.Scanner; import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.InputMismatchException; import javax.xml.parsers.ParserConfigurationException; @@ -36,9 +39,6 @@ import com.taobao.middleware.cli.annotations.Name; import com.taobao.middleware.cli.annotations.Option; import com.taobao.middleware.cli.annotations.Summary; -import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_ERROR; -import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT; - /** * @author hengyunabc 2018-10-26 * @@ -47,15 +47,17 @@ import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT; @Summary("Bootstrap Arthas") @Description("EXAMPLES:\n" + " java -jar arthas-boot.jar \n" + " java -jar arthas-boot.jar --target-ip 0.0.0.0\n" + " java -jar arthas-boot.jar --telnet-port 9999 --http-port -1\n" - + " java -jar arthas-boot.jar --tunnel-server 'ws://192.168.10.11:7777/ws'\n" + + " java -jar arthas-boot.jar --username admin --password \n" + + " java -jar arthas-boot.jar --tunnel-server 'ws://192.168.10.11:7777/ws' --app-name demoapp\n" + " java -jar arthas-boot.jar --tunnel-server 'ws://192.168.10.11:7777/ws' --agent-id bvDOe8XbTM2pQWjF4cfw\n" + " java -jar arthas-boot.jar --stat-url 'http://192.168.10.11:8080/api/stat'\n" + " java -jar arthas-boot.jar -c 'sysprop; thread' \n" + " java -jar arthas-boot.jar -f batch.as \n" - + " java -jar arthas-boot.jar --use-version 3.4.3\n" + + " java -jar arthas-boot.jar --use-version 3.5.2\n" + " java -jar arthas-boot.jar --versions\n" - + " java -jar arthas-boot.jar --select arthas-demo\n" + + " java -jar arthas-boot.jar --select math-game\n" + " java -jar arthas-boot.jar --session-timeout 3600\n" + " java -jar arthas-boot.jar --attach-only\n" + + " java -jar arthas-boot.jar --disabled-commands stop,dump\n" + " java -jar arthas-boot.jar --repo-mirror aliyun --use-http\n" + "WIKI:\n" + " https://arthas.aliyun.com/doc\n") public class Bootstrap { @@ -67,9 +69,9 @@ public class Bootstrap { private boolean help = false; private long pid = -1; - private String targetIp = DEFAULT_TARGET_IP; - private int telnetPort = DEFAULT_TELNET_PORT; - private int httpPort = DEFAULT_HTTP_PORT; + private String targetIp; + private Integer telnetPort; + private Integer httpPort; /** * @see com.taobao.arthas.core.config.Configure#DEFAULT_SESSION_TIMEOUT_SECONDS */ @@ -118,13 +120,26 @@ public class Bootstrap { private String tunnelServer; private String agentId; + private String appName; + + private String username; + private String password; + private String statUrl; private String select; + private String disabledCommands; + static { - ARTHAS_LIB_DIR = new File( - System.getProperty("user.home") + File.separator + ".arthas" + File.separator + "lib"); + String arthasLibDirEnv = System.getenv("ARTHAS_LIB_DIR"); + if (arthasLibDirEnv != null) { + ARTHAS_LIB_DIR = new File(arthasLibDirEnv); + } else { + ARTHAS_LIB_DIR = new File( + System.getProperty("user.home") + File.separator + ".arthas" + File.separator + "lib"); + } + try { ARTHAS_LIB_DIR.mkdirs(); } catch (Throwable t) { @@ -258,6 +273,23 @@ public class Bootstrap { this.agentId = agentId; } + @Option(longName = "app-name") + @Description("The app name") + public void setAppName(String appName) { + this.appName = appName; + } + + @Option(longName = "username") + @Description("The username") + public void setUsername(String username) { + this.username = username; + } + @Option(longName = "password") + @Description("The password") + public void setPassword(String password) { + this.password = password; + } + @Option(longName = "stat-url") @Description("The report stat url") public void setStatUrl(String statUrl) { @@ -270,6 +302,12 @@ public class Bootstrap { this.select = select; } + @Option(longName = "disabled-commands") + @Description("disable some commands ") + public void setDisabledCommands(String disabledCommands) { + this.disabledCommands = disabledCommands; + } + public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { @@ -325,16 +363,16 @@ public class Bootstrap { // check telnet/http port long telnetPortPid = -1; long httpPortPid = -1; - if (bootstrap.getTelnetPort() > 0) { - telnetPortPid = SocketUtils.findTcpListenProcess(bootstrap.getTelnetPort()); + if (bootstrap.getTelnetPortOrDefault() > 0) { + telnetPortPid = SocketUtils.findTcpListenProcess(bootstrap.getTelnetPortOrDefault()); if (telnetPortPid > 0) { - AnsiLog.info("Process {} already using port {}", telnetPortPid, bootstrap.getTelnetPort()); + AnsiLog.info("Process {} already using port {}", telnetPortPid, bootstrap.getTelnetPortOrDefault()); } } - if (bootstrap.getHttpPort() > 0) { - httpPortPid = SocketUtils.findTcpListenProcess(bootstrap.getHttpPort()); + if (bootstrap.getHttpPortOrDefault() > 0) { + httpPortPid = SocketUtils.findTcpListenProcess(bootstrap.getHttpPortOrDefault()); if (httpPortPid > 0) { - AnsiLog.info("Process {} already using port {}", httpPortPid, bootstrap.getHttpPort()); + AnsiLog.info("Process {} already using port {}", httpPortPid, bootstrap.getHttpPortOrDefault()); } } @@ -357,7 +395,7 @@ public class Bootstrap { if (httpPortPid > 0 && pid != httpPortPid) { AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.", - pid, bootstrap.getHttpPort()); + pid, bootstrap.getHttpPortOrDefault()); AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it first with running the 'stop' command.", httpPortPid); AnsiLog.error("2. Or try to use different http port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port 9999", httpPortPid); @@ -461,10 +499,10 @@ public class Bootstrap { AnsiLog.info("arthas home: " + arthasHomeDir); if (telnetPortPid > 0 && pid == telnetPortPid) { - AnsiLog.info("The target process already listen port {}, skip attach.", bootstrap.getTelnetPort()); + AnsiLog.info("The target process already listen port {}, skip attach.", bootstrap.getTelnetPortOrDefault()); } else { //double check telnet port and pid before attach - telnetPortPid = findProcessByTelnetClient(arthasHomeDir.getAbsolutePath(), bootstrap.getTelnetPort()); + telnetPortPid = findProcessByTelnetClient(arthasHomeDir.getAbsolutePath(), bootstrap.getTelnetPortOrDefault()); checkTelnetPortPid(bootstrap, telnetPortPid, pid); // start arthas-core.jar @@ -473,12 +511,21 @@ public class Bootstrap { attachArgs.add(new File(arthasHomeDir, "arthas-core.jar").getAbsolutePath()); attachArgs.add("-pid"); attachArgs.add("" + pid); - attachArgs.add("-target-ip"); - attachArgs.add(bootstrap.getTargetIp()); - attachArgs.add("-telnet-port"); - attachArgs.add("" + bootstrap.getTelnetPort()); - attachArgs.add("-http-port"); - attachArgs.add("" + bootstrap.getHttpPort()); + if (bootstrap.getTargetIp() != null) { + attachArgs.add("-target-ip"); + attachArgs.add(bootstrap.getTargetIp()); + } + + if (bootstrap.getTelnetPort() != null) { + attachArgs.add("-telnet-port"); + attachArgs.add("" + bootstrap.getTelnetPort()); + } + + if (bootstrap.getHttpPort() != null) { + attachArgs.add("-http-port"); + attachArgs.add("" + bootstrap.getHttpPort()); + } + attachArgs.add("-core"); attachArgs.add(new File(arthasHomeDir, "arthas-core.jar").getAbsolutePath()); attachArgs.add("-agent"); @@ -488,6 +535,20 @@ public class Bootstrap { attachArgs.add("" + bootstrap.getSessionTimeout()); } + if (bootstrap.getAppName() != null) { + attachArgs.add("-app-name"); + attachArgs.add(bootstrap.getAppName()); + } + + if (bootstrap.getUsername() != null) { + attachArgs.add("-username"); + attachArgs.add(bootstrap.getUsername()); + } + if (bootstrap.getPassword() != null) { + attachArgs.add("-password"); + attachArgs.add(bootstrap.getPassword()); + } + if (bootstrap.getTunnelServer() != null) { attachArgs.add("-tunnel-server"); attachArgs.add(bootstrap.getTunnelServer()); @@ -501,6 +562,11 @@ public class Bootstrap { attachArgs.add(bootstrap.getStatUrl()); } + if (bootstrap.getDisabledCommands() != null){ + attachArgs.add("-disabled-commands"); + attachArgs.add(bootstrap.getDisabledCommands()); + } + AnsiLog.info("Try to attach process " + pid); AnsiLog.debug("Start arthas-core.jar args: " + attachArgs); ProcessUtils.startArthasCore(pid, attachArgs); @@ -538,10 +604,10 @@ public class Bootstrap { } // telnet port ,ip - telnetArgs.add(bootstrap.getTargetIp()); - telnetArgs.add("" + bootstrap.getTelnetPort()); + telnetArgs.add(bootstrap.getTargetIpOrDefault()); + telnetArgs.add("" + bootstrap.getTelnetPortOrDefault()); - AnsiLog.info("arthas-client connect {} {}", bootstrap.getTargetIp(), bootstrap.getTelnetPort()); + AnsiLog.info("arthas-client connect {} {}", bootstrap.getTargetIpOrDefault(), bootstrap.getTelnetPortOrDefault()); AnsiLog.debug("Start arthas-client.jar args: " + telnetArgs); // fix https://github.com/alibaba/arthas/issues/833 @@ -552,10 +618,10 @@ public class Bootstrap { private static void checkTelnetPortPid(Bootstrap bootstrap, long telnetPortPid, long targetPid) { if (telnetPortPid > 0 && targetPid != telnetPortPid) { AnsiLog.error("The telnet port {} is used by process {} instead of target process {}, you will connect to an unexpected process.", - bootstrap.getTelnetPort(), telnetPortPid, targetPid); + bootstrap.getTelnetPortOrDefault(), telnetPortPid, targetPid); AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it first with running the 'stop' command.", telnetPortPid); - AnsiLog.error("2. Or try to stop the existing arthas instance: java -jar arthas-client.jar 127.0.0.1 {} -c \"stop\"", bootstrap.getTelnetPort()); + AnsiLog.error("2. Or try to stop the existing arthas instance: java -jar arthas-client.jar 127.0.0.1 {} -c \"stop\"", bootstrap.getTelnetPortOrDefault()); AnsiLog.error("3. Or try to use different telnet port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port -1"); System.exit(1); } @@ -704,14 +770,38 @@ public class Bootstrap { return targetIp; } - public int getTelnetPort() { + public String getTargetIpOrDefault() { + if (this.targetIp == null) { + return DEFAULT_TARGET_IP; + } else { + return this.targetIp; + } + } + + public Integer getTelnetPort() { return telnetPort; } + + public int getTelnetPortOrDefault() { + if (this.telnetPort == null) { + return DEFAULT_TELNET_PORT; + } else { + return this.telnetPort; + } + } - public int getHttpPort() { + public Integer getHttpPort() { return httpPort; } + public int getHttpPortOrDefault() { + if (this.httpPort == null) { + return DEFAULT_HTTP_PORT; + } else { + return this.httpPort; + } + } + public String getCommand() { return command; } @@ -760,6 +850,10 @@ public class Bootstrap { return agentId; } + public String getAppName() { + return appName; + } + public String getStatUrl() { return statUrl; } @@ -767,4 +861,16 @@ public class Bootstrap { public String getSelect() { return select; } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getDisabledCommands() { + return disabledCommands; + } } diff --git a/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java b/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java index 49d184937..ce0b11afa 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java +++ b/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java @@ -65,7 +65,7 @@ public class ProcessUtils { } if (processMap.isEmpty()) { - AnsiLog.info("Can not find java process. Try to pass in command line."); + AnsiLog.info("Can not find java process. Try to run `jps` command lists the instrumented Java HotSpot VMs on the target system."); return -1; } @@ -233,13 +233,13 @@ public class ProcessUtils { String javaHome = findJavaHome(); // find java/java.exe - File javaPath = findJava(); + File javaPath = findJava(javaHome); if (javaPath == null) { throw new IllegalArgumentException( "Can not find java/java.exe executable file under java home: " + javaHome); } - File toolsJar = findToolsJar(); + File toolsJar = findToolsJar(javaHome); if (JavaVersionUtils.isLessThanJava9()) { if (toolsJar == null || !toolsJar.exists()) { @@ -313,8 +313,8 @@ public class ProcessUtils { // find arthas-client.jar URLClassLoader classLoader = new URLClassLoader( new URL[]{new File(arthasHomeDir, "arthas-client.jar").toURI().toURL()}); - Class telnetConsoleClas = classLoader.loadClass("com.taobao.arthas.client.TelnetConsole"); - Method processMethod = telnetConsoleClas.getMethod("process", String[].class); + Class telnetConsoleClass = classLoader.loadClass("com.taobao.arthas.client.TelnetConsole"); + Method processMethod = telnetConsoleClass.getMethod("process", String[].class); //redirect System.out/System.err PrintStream originSysOut = System.out; @@ -354,8 +354,7 @@ public class ProcessUtils { } } - private static File findJava() { - String javaHome = findJavaHome(); + private static File findJava(String javaHome) { String[] paths = { "bin/java", "bin/java.exe", "../bin/java", "../bin/java.exe" }; List javaList = new ArrayList(); @@ -389,12 +388,11 @@ public class ProcessUtils { return javaList.get(0); } - private static File findToolsJar() { + private static File findToolsJar(String javaHome) { if (JavaVersionUtils.isGreaterThanJava8()) { return null; } - String javaHome = findJavaHome(); File toolsJar = new File(javaHome, "lib/tools.jar"); if (!toolsJar.exists()) { toolsJar = new File(javaHome, "../lib/tools.jar"); diff --git a/boot/src/test/java/com/taobao/arthas/boot/DownloadUtilsTest.java b/boot/src/test/java/com/taobao/arthas/boot/DownloadUtilsTest.java index a681ef112..2b5f09c81 100644 --- a/boot/src/test/java/com/taobao/arthas/boot/DownloadUtilsTest.java +++ b/boot/src/test/java/com/taobao/arthas/boot/DownloadUtilsTest.java @@ -3,6 +3,8 @@ package com.taobao.arthas.boot; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.TimeZone; +import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Rule; @@ -29,13 +31,16 @@ public class DownloadUtilsTest { @Test public void testAliyunDownload() throws IOException { - String version = "3.3.7"; - File folder = rootFolder.newFolder(); - System.err.println(folder.getAbsolutePath()); - DownloadUtils.downArthasPackaging("aliyun", false, version, folder.getAbsolutePath()); - - File as = new File(folder, version + File.separator + "arthas" + File.separator + "as.sh"); - Assert.assertTrue(as.exists()); + // fix travis-ci failed problem + if (TimeUnit.MILLISECONDS.toHours(TimeZone.getDefault().getOffset(System.currentTimeMillis())) == 8) { + String version = "3.3.7"; + File folder = rootFolder.newFolder(); + System.err.println(folder.getAbsolutePath()); + DownloadUtils.downArthasPackaging("aliyun", false, version, folder.getAbsolutePath()); + + File as = new File(folder, version + File.separator + "arthas" + File.separator + "as.sh"); + Assert.assertTrue(as.exists()); + } } @Test diff --git a/bytekit/README.md b/bytekit/README.md deleted file mode 100644 index 92a56d99e..000000000 --- a/bytekit/README.md +++ /dev/null @@ -1,222 +0,0 @@ - - -## ByteKit - - -## 目标 - -1. 之前的Arthas里的字节码增强,是通过asm来处理的,代码逻辑不好修改,理解困难 -1. 基于ASM提供更高层的字节码处理能力,面向诊断/APM领域,不是通用的字节码库 -1. ByteKit期望能提供一套简洁的API,让开发人员可以比较轻松的完成字节码增强 - -## 对比 - -| 功能 | 函数Enter/Exit注入点 | 绑定数据 | inline | 防止重复增强 | 避免装箱/拆箱开销 |origin调用替换 | `@ExceptionHandler` | -| ---- | ---- |---- | :----: |:----: | :----: |:----: | :----: | -| ByteKit | `@AtEnter`
`@AtExit`
`@AtExceptionExit`
`@AtFieldAccess`
`@AtInvoke`
`@AtInvokeException`
`@AtLine`
`@AtSyncEnter`
`@AtSyncExit`
`@AtThrow`| this/args/return/throw
field
locals
子调用入参/返回值/子调用异常
line number|✓|✓|✓|✓|✓| -| ByteBuddy | `OnMethodEnter`
`@OnMethodExit`
`@OnMethodExit#onThrowable()`| this/args/return/throw
field
locals|✓|✗|✓|✓|✓| -| 传统AOP | `Enter`
`Exit`
`Exception` |this/args/return/throw|✗|✗|✗|✗|✗ - - -## 特性 - -### 1. 丰富的注入点支持 - -* `@AtEnter` 函数入口 -* `@AtExit` 函数退出 -* `@AtExceptionExit` 函数抛出异常 -* `@AtFieldAccess` 访问field -* `@AtInvoke` 在method里的子函数调用 -* `@AtInvokeException` 在method里的子函数调用抛出异常 -* `@AtLine` 在指定行号 -* `@AtSyncEnter` 进入同步块,比如`synchronized`块 -* `@AtSyncExit` 退出同步块 -* `@AtThrow` 代码里显式`throw`异常点 - - -### 2. 动态的Binding - -* `@Binding.This` this对象 -* `@@Binding.Class` Class对象 -* `@Binding.Method` 函数调用的 Method 对象 -* `@Binding.MethodName` 函数的名字 -* `@Binding.MethodDesc` 函数的desc -* `@Binding.Return` 函数调用的返回值 -* `@Binding.Throwable` 函数里抛出的异常 -* `@Binding.Args` 函数调用的入参 -* `@Binding.ArgNames` 函数调用的入参的名字 - - -* `@Binding.LocalVars` 局部变量 -* `@Binding.LocalVarNames` 局部变量的名字 -* `@Binding.Field` field对象属性字段 - - -* `@Binding.InvokeArgs` method里的子函数调用的入参 -* `@Binding.InvokeReturn` method里的子函数调用的返回值 -* `@Binding.InvokeMethodName` method里的子函数调用的名字 -* `@Binding.InvokeMethodOwner` method里的子函数调用的类名 -* `@Binding.InvokeMethodDeclaration` method里的子函数调用的desc - - -* `@Binding.Line` 行号 -* `@Binding.Monitor` 同步块里监控的对象 - - -### 3. 可编程的异常处理 - -* `@ExceptionHandler` 在插入的增强代码,可以用`try/catch`块包围起来 - -### 4. inline支持 - -增强的代码 和 异常处理代码都可以通过 inline技术内联到原来的类里,达到最理想的增强效果。 - -### 5. invokeOrigin 技术 - -通常,我们要增强一个类,就想要办法在函数前后插入一个static的回调函数,但这样子局限太大。那么有没有更灵活的方式呢? - -比如有一个 hello() 函数: - -```java - public String hello(String str) { - return "hello " + str; - } -``` - -我们想对它做增强,那么可以编写下面的代码: - -```java - public String hello(String str) { - System.out.println("before"); - Object value = InstrumentApi.invokeOrigin(); - System.out.println("after, result: " + value); - return object; - } -``` - -增强后的结果是: - -```java - public String hello(String str) { - System.out.println("before"); - Object value = "hello " + str; - System.out.println("after, result: " + value); - return object; - } -``` - -**这种方式可以随意插入代码,非常灵活。** - -## 示例 - -以`ByteKitDemo.java`为例说明,[[查看源文件](src/test/java/com/example/ByteKitDemo.java)]。 - -### 1. 定义注入点和Binding数据 - -* 在下面的 SampleInterceptor 时定义了要注入 `@AtEnter`/`@AtExit`/`@AtExceptionExit`三个地方, -* 用`@Binding`绑定了不同的数据 -* 在`@AtEnter`里配置了 `inline = true`,则说明插入的`SampleInterceptor#atEnter`函数本身会被inline掉 -* 配置了 `suppress = RuntimeException.class` 和 `suppressHandler = PrintExceptionSuppressHandler.class`,说明插入的代码会被 `try/catch` 包围 - -```java - public static class SampleInterceptor { - - @AtEnter(inline = true, suppress = RuntimeException.class, suppressHandler = PrintExceptionSuppressHandler.class) - public static void atEnter(@Binding.This Object object, - @Binding.Class Object clazz, - @Binding.Args Object[] args, - @Binding.MethodName String methodName, - @Binding.MethodDesc String methodDesc) { - System.out.println("atEnter, args[0]: " + args[0]); - } - - @AtExit(inline = true) - public static void atExit(@Binding.Return Object returnObject) { - System.out.println("atExit, returnObject: " + returnObject); - } - - @AtExceptionExit(inline = true, onException = RuntimeException.class) - public static void atExceptionExit(@Binding.Throwable RuntimeException ex, - @Binding.Field(name = "exceptionCount") int exceptionCount) { - System.out.println("atExceptionExit, ex: " + ex.getMessage() + ", field exceptionCount: " + exceptionCount); - } - } -``` - -### 2. @ExceptionHandler - -在上面的 `@AtEnter`配置里,生成的代码会被 try/catch 包围,那么具体的内容是在`PrintExceptionSuppressHandler`里 - -```java - public static class PrintExceptionSuppressHandler { - - @ExceptionHandler(inline = true) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.out.println("exception handler: " + clazz); - e.printStackTrace(); - } - } -``` - -### 3. 查看反编译结果 - -原始的Sample类是: - -```java - public static class Sample { - private int exceptionCount = 0; - - public String hello(String str, boolean exception) { - if (exception) { - exceptionCount++; - throw new RuntimeException("test exception, str: " + str); - } - return "hello " + str; - } - } -``` - -增强后的字节码,再反编译: - -```java -package com.example; - -public static class ByteKitDemo.Sample { - private int exceptionCount = 0; - - public String hello(String string, boolean bl) { - try { - String string2 = "(Ljava/lang/String;Z)Ljava/lang/String;"; - String string3 = "hello"; - Object[] arrobject = new Object[]{string, new Boolean(bl)}; - Class class_ = ByteKitDemo.Sample.class; - ByteKitDemo.Sample sample = this; - System.out.println("atEnter, args[0]: " + arrobject[0]); - } - catch (RuntimeException runtimeException) { - Class class_ = ByteKitDemo.Sample.class; - RuntimeException runtimeException2 = runtimeException; - System.out.println("exception handler: " + class_); - runtimeException2.printStackTrace(); - } - try { - String string4; - void str; - void exception; - if (exception != false) { - ++this.exceptionCount; - throw new RuntimeException("test exception, str: " + (String)str); - } - String string5 = string4 = "hello " + (String)str; - System.out.println("atExit, returnObject: " + string5); - return string4; - } - catch (RuntimeException runtimeException) { - int n = this.exceptionCount; - RuntimeException runtimeException3 = runtimeException; - System.out.println("atExceptionExit, ex: " + runtimeException3.getMessage() + ", field exceptionCount: " + n); - throw runtimeException; - } - } -} -``` diff --git a/bytekit/pom.xml b/bytekit/pom.xml deleted file mode 100644 index ae50ec410..000000000 --- a/bytekit/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - com.taobao.arthas - arthas-all - 3.4.4-SNAPSHOT - ../pom.xml - - arthas-bytekit - arthas-bytekit - - - - com.taobao.arthas - arthas-common - ${project.version} - - - - com.alibaba.arthas - arthas-repackage-asm - - - - org.benf - cfr - provided - true - - - - net.bytebuddy - byte-buddy - provided - true - - - - net.bytebuddy - byte-buddy-agent - provided - true - - - - - junit - junit - test - - - - org.assertj - assertj-core - test - true - - - - org.springframework.boot - spring-boot-starter-test - 1.5.9.RELEASE - test - true - - - com.taobao.arthas - arthas-demo - ${project.version} - test - - - - - - arthas-bytekit - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.6 - 1.6 - UTF-8 - true - - - - - - diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/ByteKit.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/ByteKit.java deleted file mode 100644 index 281ce7431..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/ByteKit.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.taobao.arthas.bytekit; - -import java.util.List; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorClassParser; -import com.taobao.arthas.bytekit.asm.matcher.ClassMatcher; -import com.taobao.arthas.bytekit.asm.matcher.MethodMatcher; - -public class ByteKit { - - - private ClassMatcher classMatcher; - private MethodMatcher methodMatcher; - - private Class interceptorClass; - - private InterceptorClassParser interceptorClassParser; - - private List interceptorProcessors; -} - diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/ClassLoaderAwareClassWriter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/ClassLoaderAwareClassWriter.java deleted file mode 100644 index fb46dbca1..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/ClassLoaderAwareClassWriter.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -import com.alibaba.arthas.deps.org.objectweb.asm.ClassReader; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassWriter; - -/** - * @author vlinux - * @author hengyunabc 2020-05-29 - * - */ -public class ClassLoaderAwareClassWriter extends ClassWriter { - private ClassLoader classLoader; - - public ClassLoaderAwareClassWriter(int flags, ClassLoader loader) { - this(null, flags, loader); - } - - public ClassLoaderAwareClassWriter(ClassReader classReader, int flags, ClassLoader loader) { - super(classReader, flags); - this.classLoader = loader; - } - - /* - * 注意,为了自动计算帧的大小,有时必须计算两个类共同的父类。 - * 缺省情况下,ClassWriter将会在getCommonSuperClass方法中计算这些,通过在加载这两个类进入虚拟机时,使用反射API来计算。 - * 但是,如果你将要生成的几个类相互之间引用,这将会带来问题,因为引用的类可能还不存在。 - * 在这种情况下,你可以重写getCommonSuperClass方法来解决这个问题。 - * - * 通过重写 getCommonSuperClass() 方法,更正获取ClassLoader的方式,改成使用指定ClassLoader的方式进行。 - * 规避了原有代码采用Object.class.getClassLoader()的方式 - */ - @Override - protected String getCommonSuperClass(String type1, String type2) { - Class c, d; - try { - c = Class.forName(type1.replace('/', '.'), false, classLoader); - d = Class.forName(type2.replace('/', '.'), false, classLoader); - } catch (Exception e) { - throw new RuntimeException(e); - } - if (c.isAssignableFrom(d)) { - return type1; - } - if (d.isAssignableFrom(c)) { - return type2; - } - if (c.isInterface() || d.isInterface()) { - return "java/lang/Object"; - } else { - do { - c = c.getSuperclass(); - } while (!c.isAssignableFrom(d)); - return c.getName().replace('.', '/'); - } - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/InliningAdapter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/InliningAdapter.java deleted file mode 100644 index 6ebd30f48..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/InliningAdapter.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -import com.alibaba.arthas.deps.org.objectweb.asm.Label; -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.LocalVariablesSorter; - -/** - * Adapter for to be inlined code. - * - * This adapter does all parameter renaming and replacing of the RETURN opcodes - * - * - */ -public class InliningAdapter extends LocalVariablesSorter { - private final Label end; - private LocalVariablesSorter lvs; - - public InliningAdapter(LocalVariablesSorter mv, int access, String desc, Label end) { - super(Opcodes.ASM9, access, desc, mv); - this.end = end; - this.lvs = mv; - -// int off = (access & Opcodes.ACC_STATIC) != 0 ? -// 0 : 1; -// Type[] args = Type.getArgumentTypes(desc); -// for (int i = args.length - 1; i >= 0; i--) { -// super.visitVarInsn(args[i].getOpcode( -// Opcodes.ISTORE), i + off); -// } -// if (off > 0) { -// super.visitVarInsn(Opcodes.ASTORE, 0); -// } - - // save args to local vars - int off = (access & Opcodes.ACC_STATIC) != 0 ? 0 : 1; - Type[] args = Type.getArgumentTypes(desc); - int argsOff = off; - - for(int i = 0; i < args.length; ++i) { - argsOff += args[i].getSize(); - } - - for(int i = args.length - 1; i >= 0; --i) { - argsOff -= args[i].getSize(); - this.visitVarInsn(args[i].getOpcode(Opcodes.ISTORE), argsOff); - } - - // this - if (off > 0) { - this.visitVarInsn(Opcodes.ASTORE, 0); - } - } - - @Override - public void visitInsn(int opcode) { - if (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) { - super.visitJumpInsn(Opcodes.GOTO, end); - } else { - super.visitInsn(opcode); - } - } - - @Override - public void visitMaxs(int stack, int locals) { -// super.visitMaxs(stack, locals); - } - - @Override - protected int newLocalMapping(Type type) { - return lvs.newLocal(type); - } - - @Override - public void visitVarInsn(int opcode, int var) { - super.visitVarInsn(opcode, var + this.firstLocal); - } - @Override - public void visitIincInsn(int var, int increment) { - super.visitIincInsn(var + this.firstLocal, increment); - } - @Override - public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { - super.visitLocalVariable(name, desc, signature, start, end, index + this.firstLocal); - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodCallInliner.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodCallInliner.java deleted file mode 100644 index dd8cad220..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodCallInliner.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Label; -import com.alibaba.arthas.deps.org.objectweb.asm.MethodVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.GeneratorAdapter; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -/** - * @author hengyunabc 2018-01-31 - * - */ -public abstract class MethodCallInliner extends GeneratorAdapter { - public class CatchBlock { - - private Label start; - private Label handler; - private String type; - private Label end; - - public CatchBlock(Label start, Label end, Label handler, String type) { - this.start = start; - this.end = end; - this.handler = handler; - this.type = type; - } - - } - - private final MethodNode toBeInlined; - private List blocks = new ArrayList(); - private boolean inlining; - private boolean afterInlining; - - public MethodCallInliner(int access, String name, String desc, MethodVisitor mv, - MethodNode toBeInlined) { - super(Opcodes.ASM9, mv, access, name, desc); - this.toBeInlined = toBeInlined; - } - - @Override - public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { - if (!shouldBeInlined(owner, name, desc)) { - mv.visitMethodInsn(opcode, owner, name, desc, itf); - return; - } - - // if (this.analyzerAdapter != null) { - // mv = new MergeFrameAdapter(this.api, this.analyzerAdapter, - // (MethodVisitor)mv); - // } - - Label end = new Label(); - inlining = true; - toBeInlined.instructions.resetLabels(); - - // pass the to be inlined method through the inlining adapter to this - toBeInlined.accept(new InliningAdapter(this, toBeInlined.access, toBeInlined.desc, end)); - inlining = false; - afterInlining = true; - - // visit the end label - super.visitLabel(end); - - // box the return value if necessary - // Type returnType = - // Type.getMethodType(toBeInlined.desc).getReturnType(); - // valueOf(returnType); - - } - - abstract boolean shouldBeInlined(String owner, String name, String desc); - - @Override - public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { - if (!inlining) { - blocks.add(new CatchBlock(start, end, handler, type)); - } else { - super.visitTryCatchBlock(start, end, handler, type); - } - } - - @Override - public void visitMaxs(int stack, int locals) { - for (CatchBlock b : blocks) - super.visitTryCatchBlock(b.start, b.end, b.handler, b.type); - super.visitMaxs(stack, locals); - } - - @Override - public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) { - // swallow - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodInfo.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodInfo.java deleted file mode 100644 index 8188d4d7d..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodInfo.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -/** - * - * @author hengyunabc 2019-03-18 - * - */ -public class MethodInfo { - - private String owner; - - private int access; - private String name; - private String desc; - - public int getAccess() { - return access; - } - - public void setAccess(int access) { - this.access = access; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodProcessor.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodProcessor.java deleted file mode 100644 index 31030b695..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MethodProcessor.java +++ /dev/null @@ -1,784 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.Method; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FrameNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.IincInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.IntInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.JumpInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LdcInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TryCatchBlockNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TypeInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.VarInsnNode; -import com.taobao.arthas.bytekit.asm.location.filter.DefaultLocationFilter; -import com.taobao.arthas.bytekit.asm.location.filter.LocationFilter; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; - -public class MethodProcessor { - - private String owner; - /** - * maybe null - */ - private ClassNode classNode; - private MethodNode methodNode; - - private final Type[] argumentTypes; - private final Type returnType; - - private int nextLocals; - - private static final Type BYTE_TYPE = Type.getObjectType("java/lang/Byte"); - - private static final Type BOOLEAN_TYPE = Type.getObjectType("java/lang/Boolean"); - - private static final Type SHORT_TYPE = Type.getObjectType("java/lang/Short"); - - private static final Type CHARACTER_TYPE = Type.getObjectType("java/lang/Character"); - - private static final Type INTEGER_TYPE = Type.getObjectType("java/lang/Integer"); - - private static final Type FLOAT_TYPE = Type.getObjectType("java/lang/Float"); - - private static final Type LONG_TYPE = Type.getObjectType("java/lang/Long"); - - private static final Type DOUBLE_TYPE = Type.getObjectType("java/lang/Double"); - - private static final Type OBJECT_TYPE = Type.getObjectType("java/lang/Object"); - - private static final Type STRING_TYPE = Type.getObjectType("java/lang/String"); - - private static final Type THROWABLE_TYPE = Type.getObjectType("java/lang/Throwable"); - - private static final Type NUMBER_TYPE = Type.getObjectType("java/lang/Number"); - - private static final Type OBJECT_ARRAY_TYPE = Type.getType(Object[].class); - - private static final Method BOOLEAN_VALUE = Method.getMethod("boolean booleanValue()"); - - private static final Method CHAR_VALUE = Method.getMethod("char charValue()"); - - private static final Method INT_VALUE = Method.getMethod("int intValue()"); - - private static final Method FLOAT_VALUE = Method.getMethod("float floatValue()"); - - private static final Method LONG_VALUE = Method.getMethod("long longValue()"); - - private static final Method DOUBLE_VALUE = Method.getMethod("double doubleValue()"); - - public static final String DEFAULT_INNER_VARIABLE_PREFIX = "_$bytekit$_"; - - private final LabelNode interceptorVariableStartLabelNode = new LabelNode(); - private final LabelNode interceptorVariableEndLabelNode = new LabelNode(); - - private AbstractInsnNode enterInsnNode; - // TODO 这里应该直接从 InsnList 里来取?因为插入代码之后,这个会改变的。 - // TODO 这个没有被使用到,是不是没用的?? - private AbstractInsnNode lastInsnNode; - - /** - * 保留中间生成的 variable的名字 - */ - private boolean keepLocalVariableNames; - - private String innerVariablePrefix; - - private String returnVariableName; - private String throwVariableName; - private String invokeArgsVariableName; - private String monitorVariableName; - private LocalVariableNode returnVariableNode = null; - private LocalVariableNode throwVariableNode = null; - private LocalVariableNode invokeArgsVariableNode = null; - private LocalVariableNode monitorVariableNode = null; // for synchronized - - private String invokeReturnVariablePrefix; - private Map invokeReturnVariableNodeMap = new HashMap(); - - private TryCatchBlock tryCatchBlock = null; - - private LocationFilter locationFilter = new DefaultLocationFilter(); - - public MethodProcessor(final ClassNode classNode, final MethodNode methodNode) { - this(classNode, methodNode, false); - } - - public MethodProcessor(final ClassNode classNode, final MethodNode methodNode, LocationFilter locationFilter) { - this(classNode, methodNode, false); - this.locationFilter = locationFilter; - } - - public MethodProcessor(final ClassNode classNode, final MethodNode methodNode, boolean keepLocalVariableNames) { - this(classNode.name, methodNode, keepLocalVariableNames); - this.classNode = classNode; - } - - public MethodProcessor(final String owner, final MethodNode methodNode, boolean keepLocalVariableNames) { - this.owner = owner; - this.methodNode = methodNode; - this.nextLocals = methodNode.maxLocals; - this.argumentTypes = Type.getArgumentTypes(methodNode.desc); - this.returnType = Type.getReturnType(methodNode.desc); - this.keepLocalVariableNames = keepLocalVariableNames; - - // find enter & exit instruction. - if (isConstructor()) { - this.enterInsnNode = findInitConstructorInstruction(); - } else { - this.enterInsnNode = methodNode.instructions.getFirst(); - } - - // when the method is empty, both enterInsnNode and lastInsnNode are Opcodes.RETURN ; - this.lastInsnNode = methodNode.instructions.getLast(); - - // setup interceptor variables start/end label. - this.methodNode.instructions.insertBefore(this.enterInsnNode, this.interceptorVariableStartLabelNode); - this.methodNode.instructions.insert(this.lastInsnNode, this.interceptorVariableEndLabelNode); - - initInnerVariablePrefix(); - } - public MethodProcessor(final String owner, final MethodNode methodNode) { - this(owner, methodNode, false); - } - - private void initInnerVariablePrefix() { - String prefix = DEFAULT_INNER_VARIABLE_PREFIX; - int count = 0; - while(existLocalVariableWithPrefix(prefix)) { - prefix = DEFAULT_INNER_VARIABLE_PREFIX + count + "_"; - count++; - } - this.innerVariablePrefix = prefix; - - returnVariableName = innerVariablePrefix + "_return"; - throwVariableName = innerVariablePrefix + "_throw"; - invokeArgsVariableName = innerVariablePrefix + "_invokeArgs"; - monitorVariableName = innerVariablePrefix + "_monitor"; - - invokeReturnVariablePrefix = innerVariablePrefix + "_invokeReturn_"; - } - - private boolean existLocalVariableWithPrefix(String prefix) { - for (LocalVariableNode variableNode : this.methodNode.localVariables) { - if (variableNode.name.startsWith(prefix)) { - return true; - } - } - return false; - } - - public LocalVariableNode initMonitorVariableNode() { - if (monitorVariableNode == null) { - monitorVariableNode = this.addInterceptorLocalVariable(monitorVariableName, OBJECT_TYPE.getDescriptor()); - } - return monitorVariableNode; - } - - public LocalVariableNode initThrowVariableNode() { - if (throwVariableNode == null) { - throwVariableNode = this.addInterceptorLocalVariable(throwVariableName, THROWABLE_TYPE.getDescriptor()); - } - return throwVariableNode; - } - - public LocalVariableNode initInvokeArgsVariableNode() { - if (invokeArgsVariableNode == null) { - invokeArgsVariableNode = this.addInterceptorLocalVariable(invokeArgsVariableName, - OBJECT_ARRAY_TYPE.getDescriptor()); - } - return invokeArgsVariableNode; - } - - public LocalVariableNode initReturnVariableNode() { - if (returnVariableNode == null) { - returnVariableNode = this.addInterceptorLocalVariable(returnVariableName, returnType.getDescriptor()); - } - return returnVariableNode; - } - - /** - * - * @param name - * @param type - * @return - */ - public LocalVariableNode initInvokeReturnVariableNode(String name, Type type) { - String key = this.invokeReturnVariablePrefix + name; - LocalVariableNode variableNode = invokeReturnVariableNodeMap.get(key); - if (variableNode == null) { - variableNode = this.addInterceptorLocalVariable(key, type.getDescriptor()); - invokeReturnVariableNodeMap.put(key, variableNode); - } - return variableNode; - } - - public TryCatchBlock initTryCatchBlock() { - return initTryCatchBlock(THROWABLE_TYPE.getInternalName()); - } - - public TryCatchBlock initTryCatchBlock(String exception) { - if( this.tryCatchBlock == null) { - this.tryCatchBlock = new TryCatchBlock(methodNode, exception); - this.methodNode.instructions.insertBefore(this.getEnterInsnNode(), tryCatchBlock.getStartLabelNode()); - this.methodNode.instructions.insert(this.getLastInsnNode(), tryCatchBlock.getEndLabelNode()); - InsnList instructions = new InsnList(); - AsmOpUtils.throwException(instructions); - this.methodNode.instructions.insert(tryCatchBlock.getEndLabelNode(), instructions); - - tryCatchBlock.sort(); - } - return tryCatchBlock; - } - - AbstractInsnNode findInitConstructorInstruction() { - int nested = 0; - for (AbstractInsnNode insnNode = this.methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode - .getNext()) { - if (insnNode instanceof TypeInsnNode) { - if (insnNode.getOpcode() == Opcodes.NEW) { - // new object(). - nested++; - } - } else if (insnNode instanceof MethodInsnNode) { - final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - if (methodInsnNode.getOpcode() == Opcodes.INVOKESPECIAL && methodInsnNode.name.equals("")) { - if (--nested < 0) { - // find this() or super(). - return insnNode.getNext(); - } - } - } - } - - return null; - } - - public AbstractInsnNode getEnterInsnNode() { - return enterInsnNode; - } - - public AbstractInsnNode getLastInsnNode() { - return lastInsnNode; - } - - public String[] getParameterTypes() { - final String[] parameterTypes = new String[this.argumentTypes.length]; - for (int i = 0; i < this.argumentTypes.length; i++) { - parameterTypes[i] = this.argumentTypes[i].getClassName(); - } - - return parameterTypes; - } - - public String[] getParameterNames() { - if (this.argumentTypes.length == 0) { - return new String[0]; - } - - final List localVariableNodes = this.methodNode.localVariables; - int localVariableStartIndex = 1; - if (isStatic()) { - // static method is none this. - localVariableStartIndex = 0; - } - - if (localVariableNodes == null || localVariableNodes.size() <= localVariableStartIndex - || (this.argumentTypes.length + localVariableStartIndex) > localVariableNodes.size()) { - // make simple argument names. - final String[] names = new String[this.argumentTypes.length]; - for (int i = 0; i < this.argumentTypes.length; i++) { - final String className = this.argumentTypes[i].getClassName(); - if (className != null) { - final int findIndex = className.lastIndexOf('.'); - if (findIndex == -1) { - names[i] = className; - } else { - names[i] = className.substring(findIndex + 1); - } - } else { - names[i] = this.argumentTypes[i].getDescriptor(); - } - } - return names; - } - - // sort by index. - Collections.sort(localVariableNodes, new Comparator() { - - @Override - public int compare(LocalVariableNode o1, LocalVariableNode o2) { - return o1.index - o2.index; - } - }); - String[] names = new String[this.argumentTypes.length]; - - for (int i = 0; i < this.argumentTypes.length; i++) { - final String name = localVariableNodes.get(localVariableStartIndex++).name; - if (name != null) { - names[i] = name; - } else { - names[i] = ""; - } - } - - return names; - } - - public Type getReturnType() { - return this.returnType; - } - - private boolean hasLocalVariable(String name) { - List localVariableNodes = this.methodNode.localVariables; - if (localVariableNodes == null) { - return false; - } - - for (LocalVariableNode node : localVariableNodes) { - if (node.name.equals(name)) { - return true; - } - } - - return false; - } - - public void loadThis(final InsnList instructions) { - if (isConstructor()) { - // load this. - loadVar(instructions, 0); - } else { - if (isStatic()) { - // load null. - loadNull(instructions); - } else { - // load this. - loadVar(instructions, 0); - } - } - } - - void storeVar(final InsnList instructions, final int index) { - instructions.add(new VarInsnNode(Opcodes.ASTORE, index)); - } - - void storeInt(final InsnList instructions, final int index) { - instructions.add(new VarInsnNode(Opcodes.ISTORE, index)); - } - - void loadNull(final InsnList instructions) { - instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - } - - void loadVar(final InsnList instructions, final int index) { - instructions.add(new VarInsnNode(Opcodes.ALOAD, index)); - } - - void loadInt(final InsnList instructions, final int index) { - instructions.add(new VarInsnNode(Opcodes.ILOAD, index)); - } - - boolean isReturnCode(final int opcode) { - return opcode == Opcodes.IRETURN || opcode == Opcodes.LRETURN || opcode == Opcodes.FRETURN - || opcode == Opcodes.DRETURN || opcode == Opcodes.ARETURN || opcode == Opcodes.RETURN; - } - - Type getBoxedType(final Type type) { - switch (type.getSort()) { - case Type.BYTE: - return BYTE_TYPE; - case Type.BOOLEAN: - return BOOLEAN_TYPE; - case Type.SHORT: - return SHORT_TYPE; - case Type.CHAR: - return CHARACTER_TYPE; - case Type.INT: - return INTEGER_TYPE; - case Type.FLOAT: - return FLOAT_TYPE; - case Type.LONG: - return LONG_TYPE; - case Type.DOUBLE: - return DOUBLE_TYPE; - } - return type; - } - - void push(InsnList insnList, final int value) { - if (value >= -1 && value <= 5) { - insnList.add(new InsnNode(Opcodes.ICONST_0 + value)); - } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { - insnList.add(new IntInsnNode(Opcodes.BIPUSH, value)); - } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { - insnList.add(new IntInsnNode(Opcodes.SIPUSH, value)); - } else { - insnList.add(new LdcInsnNode(value)); - } - } - - void push(InsnList insnList, final String value) { - if (value == null) { - insnList.add(new InsnNode(Opcodes.ACONST_NULL)); - } else { - insnList.add(new LdcInsnNode(value)); - } - } - - void newArray(final InsnList insnList, final Type type) { - insnList.add(new TypeInsnNode(Opcodes.ANEWARRAY, type.getInternalName())); - } - - void dup(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP)); - } - - void dup2(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP2)); - } - - void dupX1(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP_X1)); - } - - void dupX2(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP_X2)); - } - - void pop(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.POP)); - } - - void swap(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.SWAP)); - } - - void loadArgsVar(final InsnList instructions) { - if (this.argumentTypes.length == 0) { - // null. - loadNull(instructions); - return; - } - - push(instructions, this.argumentTypes.length); - // new array - newArray(instructions, OBJECT_TYPE); - for (int i = 0; i < this.argumentTypes.length; i++) { - Type type = this.argumentTypes[i]; - dup(instructions); - push(instructions, i); - // loadArg - loadArg(instructions, this.argumentTypes, i); - // box - box(instructions, type); - // arrayStore - arrayStore(instructions, OBJECT_TYPE); - } - } - - void loadArgs(final InsnList instructions) { - for (int i = 0; i < this.argumentTypes.length; i++) { - loadArg(instructions, this.argumentTypes, i); - } - } - - void loadArg(final InsnList instructions, Type[] argumentTypes, int i) { - final int index = getArgIndex(argumentTypes, i); - final Type type = argumentTypes[i]; - instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), index)); - } - - int getArgIndex(final Type[] argumentTypes, final int arg) { - int index = isStatic() ? 0 : 1; - for (int i = 0; i < arg; i++) { - index += argumentTypes[i].getSize(); - } - return index; - } - - void box(final InsnList instructions, Type type) { - if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) { - return; - } - - if (type == Type.VOID_TYPE) { - // push null - instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - } else { - Type boxed = getBoxedType(type); - // new instance. - newInstance(instructions, boxed); - if (type.getSize() == 2) { - // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o - // dupX2 - dupX2(instructions); - // dupX2 - dupX2(instructions); - // pop - pop(instructions); - } else { - // p -> po -> opo -> oop -> o - // dupX1 - dupX1(instructions); - // swap - swap(instructions); - } - invokeConstructor(instructions, boxed, new Method("", Type.VOID_TYPE, new Type[] { type })); - } - } - - void unbox(final InsnList instructions, Type type) { - Type t = NUMBER_TYPE; - Method sig = null; - switch (type.getSort()) { - case Type.VOID: - return; - case Type.CHAR: - t = CHARACTER_TYPE; - sig = CHAR_VALUE; - break; - case Type.BOOLEAN: - t = BOOLEAN_TYPE; - sig = BOOLEAN_VALUE; - break; - case Type.DOUBLE: - sig = DOUBLE_VALUE; - break; - case Type.FLOAT: - sig = FLOAT_VALUE; - break; - case Type.LONG: - sig = LONG_VALUE; - break; - case Type.INT: - case Type.SHORT: - case Type.BYTE: - sig = INT_VALUE; - } - if (sig == null) { - instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, type.getInternalName())); - } else { - instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, t.getInternalName())); - instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, t.getInternalName(), sig.getName(), - sig.getDescriptor(), false)); - } - } - - void arrayStore(final InsnList instructions, final Type type) { - instructions.add(new InsnNode(type.getOpcode(Opcodes.IASTORE))); - } - - void arrayLoad(final InsnList instructions, final Type type) { - instructions.add(new InsnNode(type.getOpcode(Opcodes.IALOAD))); - } - - void newInstance(final InsnList instructions, final Type type) { - instructions.add(new TypeInsnNode(Opcodes.NEW, type.getInternalName())); - } - - void invokeConstructor(final InsnList instructions, final Type type, final Method method) { - String owner = type.getSort() == Type.ARRAY ? type.getDescriptor() : type.getInternalName(); - instructions - .add(new MethodInsnNode(Opcodes.INVOKESPECIAL, owner, method.getName(), method.getDescriptor(), false)); - } - - LocalVariableNode addInterceptorLocalVariable(final String name, final String desc) { - return addLocalVariable(name, desc, this.interceptorVariableStartLabelNode, - this.interceptorVariableEndLabelNode); - } - - LocalVariableNode addLocalVariable(final String name, final String desc, final LabelNode start, - final LabelNode end) { - Type type = Type.getType(desc); - int index = this.nextLocals; - this.nextLocals += type.getSize(); - methodNode.maxLocals = this.nextLocals; - final LocalVariableNode node = new LocalVariableNode(name, desc, null, start, end, index); - if (keepLocalVariableNames) { - this.methodNode.localVariables.add(node); - } - - return node; - } - - public void returnValue(final InsnList instructions) { - instructions.add(new InsnNode(this.returnType.getOpcode(Opcodes.IRETURN))); - } - - public boolean isStatic() { - return (this.methodNode.access & Opcodes.ACC_STATIC) != 0; - } - - public boolean isConstructor() { - return this.methodNode.name != null && this.methodNode.name.equals(""); - } - - public MethodNode getMethodNode() { - return methodNode; - } - - public void setMethodNode(MethodNode methodNode) { - this.methodNode = methodNode; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public ClassNode getClassNode() { - return classNode; - } - public void setClassNode(ClassNode classNode) { - this.classNode = classNode; - } - public LocationFilter getLocationFilter() { - return locationFilter; - } - - /** - * TODO 可以考虑实现修改值的功能,原理是传入的 args实际转化为一个stack上的slot,只要在inline之后,把 stack上面的对应的slot保存到想要保存的位置就可以了。 - * @param owner - * @param tmpToInlineMethodNode - */ - public void inline(String owner, MethodNode toInlineMethodNode) { - - ListIterator originMethodIter = this.methodNode.instructions.iterator(); - - while(originMethodIter.hasNext()) { - AbstractInsnNode originMethodInsnNode = originMethodIter.next(); - - if (originMethodInsnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) originMethodInsnNode; - if (methodInsnNode.owner.equals(owner) && methodInsnNode.name.equals(toInlineMethodNode.name) - && methodInsnNode.desc.equals(toInlineMethodNode.desc)) { - // 要copy一份,否则inline多次会出问题 - MethodNode tmpToInlineMethodNode = AsmUtils.copy(toInlineMethodNode); - tmpToInlineMethodNode = AsmUtils.removeLineNumbers(tmpToInlineMethodNode); - - LabelNode end = new LabelNode(); - this.methodNode.instructions.insert(methodInsnNode, end); - - InsnList instructions = new InsnList(); - - // 要先记录好当前的 maxLocals ,然后再依次把 栈上的 args保存起来 ,后面调整 VarInsnNode index里,要加上当前的 maxLocals - // save args to local vars - int currentMaxLocals = this.nextLocals; - - int off = (tmpToInlineMethodNode.access & Opcodes.ACC_STATIC) != 0 ? 0 : 1; - Type[] args = Type.getArgumentTypes(tmpToInlineMethodNode.desc); - int argsOff = off; - - for(int i = 0; i < args.length; ++i) { - argsOff += args[i].getSize(); - } - // 记录新的 maxLocals - this.nextLocals += argsOff; - methodNode.maxLocals = this.nextLocals; - - - for(int i = args.length - 1; i >= 0; --i) { - argsOff -= args[i].getSize(); -// this.visitVarInsn(args[i].getOpcode(Opcodes.ISTORE), argsOff); - - AsmOpUtils.storeVar(instructions, args[i], currentMaxLocals + argsOff); - } - - // this - if (off > 0) { -// this.visitVarInsn(Opcodes.ASTORE, 0); - AsmOpUtils.storeVar(instructions, OBJECT_TYPE, currentMaxLocals); - } - - - ListIterator inlineIterator = tmpToInlineMethodNode.instructions.iterator(); - while(inlineIterator.hasNext()) { - AbstractInsnNode abstractInsnNode = inlineIterator.next(); - if(abstractInsnNode instanceof FrameNode) { - continue; - } - - //修改inline代码中的使用到局部变量的指令的var操作数(变量slot) - if(abstractInsnNode instanceof VarInsnNode) { - VarInsnNode varInsnNode = (VarInsnNode) abstractInsnNode; - varInsnNode.var += currentMaxLocals; - } else if (abstractInsnNode instanceof IincInsnNode) { - IincInsnNode iincInsnNode = (IincInsnNode) abstractInsnNode; - iincInsnNode.var += currentMaxLocals; - } - - int opcode = abstractInsnNode.getOpcode(); - if (opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) { -// super.visitJumpInsn(Opcodes.GOTO, end); -// instructions.add(new JumpInsnNode(Opcodes.GOTO, end)); - inlineIterator.remove(); - instructions.add(new JumpInsnNode(Opcodes.GOTO, end)); - continue; - } - inlineIterator.remove(); - instructions.add(abstractInsnNode); - } - - - // 插入inline之后的代码,再删除掉原来的 MethodInsnNode - this.methodNode.instructions.insertBefore(methodInsnNode, instructions); - originMethodIter.remove(); - // try catch 块加上,然后排序 - if(this.methodNode.tryCatchBlocks != null && tmpToInlineMethodNode.tryCatchBlocks != null) { - this.methodNode.tryCatchBlocks.addAll(tmpToInlineMethodNode.tryCatchBlocks); - } - this.sortTryCatchBlock(); - } - } - } - - } - - public void sortTryCatchBlock() { - if (this.methodNode.tryCatchBlocks == null) { - return; - } - - // Compares TryCatchBlockNodes by the length of their "try" block. - Collections.sort(this.methodNode.tryCatchBlocks, new Comparator() { - @Override - public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) { - int len1 = blockLength(t1); - int len2 = blockLength(t2); - return len1 - len2; - } - - private int blockLength(TryCatchBlockNode block) { - final int startidx = methodNode.instructions.indexOf(block.start); - final int endidx = methodNode.instructions.indexOf(block.end); - return endidx - startidx; - } - }); - - // Updates the 'target' of each try catch block annotation. - for (int i = 0; i < this.methodNode.tryCatchBlocks.size(); i++) { - this.methodNode.tryCatchBlocks.get(i).updateIndex(i); - } - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MyTryCatchBlock.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MyTryCatchBlock.java deleted file mode 100644 index 3c90ec99d..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/MyTryCatchBlock.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.taobao.arthas.bytekit.asm; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TryCatchBlockNode; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; - -public class MyTryCatchBlock { - private final MethodNode methodNode; - private final LabelNode startLabelNode = new LabelNode(); - private final LabelNode endLabelNode = new LabelNode(); - private final LabelNode handlerLabelNode = new LabelNode(); - - public MyTryCatchBlock(final MethodNode methodNode) { - this.methodNode = methodNode; - - final TryCatchBlockNode tryCatchBlockNode = new TryCatchBlockNode(this.startLabelNode, this.endLabelNode, this.handlerLabelNode, "java/lang/Throwable"); - if (this.methodNode.tryCatchBlocks == null) { - this.methodNode.tryCatchBlocks = new ArrayList(); - } - this.methodNode.tryCatchBlocks.add(tryCatchBlockNode); - } - - public LabelNode getStartLabelNode() { - return this.startLabelNode; - } - - public LabelNode getEndLabelNode() { - return this.endLabelNode; - } - - public LabelNode getHandlerLabelNode() { - return this.handlerLabelNode; - } - - public void sort() { - if (this.methodNode.tryCatchBlocks == null) { - return; - } - - // Compares TryCatchBlockNodes by the length of their "try" block. - Collections.sort(this.methodNode.tryCatchBlocks, new Comparator() { - @Override - public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) { - int len1 = blockLength(t1); - int len2 = blockLength(t2); - return len1 - len2; - } - - private int blockLength(TryCatchBlockNode block) { - final int startidx = methodNode.instructions.indexOf(block.start); - final int endidx = methodNode.instructions.indexOf(block.end); - return endidx - startidx; - } - }); - - // Updates the 'target' of each try catch block annotation. - for (int i = 0; i < this.methodNode.tryCatchBlocks.size(); i++) { - this.methodNode.tryCatchBlocks.get(i).updateIndex(i); - } - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/TryCatchBlock.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/TryCatchBlock.java deleted file mode 100644 index 9068fa2aa..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/TryCatchBlock.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TryCatchBlockNode; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; - -public class TryCatchBlock { - private final MethodNode methodNode; - private final LabelNode startLabelNode = new LabelNode(); - private final LabelNode endLabelNode = new LabelNode(); - - public TryCatchBlock(final MethodNode methodNode) { - this(methodNode, Type.getType(Throwable.class).getInternalName()); - } - - public TryCatchBlock(final MethodNode methodNode, String exception) { - this.methodNode = methodNode; - - final TryCatchBlockNode tryCatchBlockNode = new TryCatchBlockNode(this.startLabelNode, this.endLabelNode, - this.endLabelNode, exception); - if (this.methodNode.tryCatchBlocks == null) { - this.methodNode.tryCatchBlocks = new ArrayList(); - } - this.methodNode.tryCatchBlocks.add(tryCatchBlockNode); - } - - public LabelNode getStartLabelNode() { - return this.startLabelNode; - } - - public LabelNode getEndLabelNode() { - return this.endLabelNode; - } - - public void sort() { - if (this.methodNode.tryCatchBlocks == null) { - return; - } - - // Compares TryCatchBlockNodes by the length of their "try" block. - Collections.sort(this.methodNode.tryCatchBlocks, new Comparator() { - @Override - public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) { - int len1 = blockLength(t1); - int len2 = blockLength(t2); - return len1 - len2; - } - - private int blockLength(TryCatchBlockNode block) { - final int startidx = methodNode.instructions.indexOf(block.start); - final int endidx = methodNode.instructions.indexOf(block.end); - return endidx - startidx; - } - }); - - // Updates the 'target' of each try catch block annotation. - for (int i = 0; i < this.methodNode.tryCatchBlocks.size(); i++) { - this.methodNode.tryCatchBlocks.get(i).updateIndex(i); - } - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/TypeHelper.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/TypeHelper.java deleted file mode 100644 index 0e8d35f80..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/TypeHelper.java +++ /dev/null @@ -1,431 +0,0 @@ -/* -* JBoss, Home of Professional Open Source -* Copyright 2008-10 Red Hat and individual contributors -* by the @authors tag. See the copyright.txt in the distribution for a -* full listing of individual contributors. -* -* This is free software; you can redistribute it and/or modify it -* under the terms of the GNU Lesser General Public License as -* published by the Free Software Foundation; either version 2.1 of -* the License, or (at your option) any later version. -* -* This software is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this software; if not, write to the Free -* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -* 02110-1301 USA, or see the FSF site: http://www.fsf.org. -* -* @authors Andrew Dinn -*/ -package com.taobao.arthas.bytekit.asm; - -/** - * Helpoer class providing static methods for manipulating type and class names, - * field and method descriptor names etc - */ -public class TypeHelper { - - public static boolean equalDescriptors(String desc1, String desc2) - { - int idx1 = 0, idx2 = 0; - int len1 = desc1.length(), len2 = desc2.length(); - while (idx1 < len1) { - // check the other has not dropped off the end - if (idx2 == len2) { - if ((idx1 == (len1 - 1)) && (desc1.charAt(idx1) == '$')) { - return true; - } - return false; - } - // check type is the same - char char1 = desc1.charAt(idx1); - char char2 = desc2.charAt(idx2); - // if we have a $ at the end of the descriptor then this means any return - // type so special case this - if ((char1 == '$' && idx1 == len1 - 1) || (char2 == '$' && idx2 == len2 - 1)) { - return true; - } - // otherwise the chars must match - if (char1 != char2) { - return false; - } - // however an L indicates a class name and we allow a classname without a package - // to match a class name with a package - if (char1 == 'L') { - // ok, ensure the names must match modulo a missing package - int end1 = idx1 + 1; - int end2 = idx2 + 1; - while (end1 < len1 && desc1.charAt(end1) != ';') { - end1++; - } - while (end2 < len2 && desc2.charAt(end2) != ';') { - end2++; - } - if (end1 == len1 || end2 == len2) { - // bad format for desc!! - return false; - } - String typeName1 = desc1.substring(idx1 + 1, end1); - String typeName2 = desc2.substring(idx2 + 1, end2); - if (!typeName1.equals(typeName2)) { - int tailIdx1 = typeName1.lastIndexOf('/'); - int tailIdx2 = typeName2.lastIndexOf('/'); - if (tailIdx1 > 0) { - if (tailIdx2 > 0) { - // both specify packages so they must be different types - return false; - } else { - // only type 1 specifies a package so type 2 should match the tail - if (!typeName2.equals(typeName1.substring(tailIdx1 + 1))) { - return false; - } - } - } else { - if (tailIdx2 > 0) { - // only type 2 specifies a package so type 1 should match the tail - if (!typeName1.equals(typeName2.substring(tailIdx2 + 1))) { - return false; - } - } else { - // neither specify packages so they must be different types - return false; - } - } - } - // skp past ';'s - idx1 = end1; - idx2 = end2; - } - idx1++; - idx2++; - } - - // check the other has not reached the end - if (idx2 != len2) { - return false; - } - - return true; - } - /** - * convert a classname from canonical form to the form used to represent it externally i.e. replace - * all dots with slashes - * - * @param className the canonical name - * @return the external name - */ - public static String externalizeClass(String className) - { - return className.replace('.', '/'); - } - - /** - * convert a classname from external form to canonical form i.e. replace - * all slashes with dots - * - * @param className the external name - * @return the canonical name - */ - public static String internalizeClass(String className) - { - String result = className; - int length = result.length(); - if (result.charAt(length - 1) == ';') { - result = result.substring(1, length - 2); - } - result = result.replace('/', '.'); - return result; - } - - /** - * convert a type name from canonical form to the form used to represent it externally i.e. - * replace primitive type names by the appropriate single letter types, class names - * by the externalized class name bracketed by 'L' and ';' and array names by the - * base type name preceded by '['. - * - * @param typeName the type name - * @return the external name - */ - public static String externalizeType(String typeName) - { - String externalName = ""; - String[] typeAndArrayIndices = typeName.split("\\["); - String baseType = typeAndArrayIndices[0].trim(); - for (int i = 1; i< typeAndArrayIndices.length; i++) { - String arrayIdx = typeAndArrayIndices[i]; - if (arrayIdx.indexOf("\\]") != 0) { - externalName += '['; - } - } - for (int i = 0; i < internalNames.length; i++) { - if (internalNames[i].equals(baseType)) { - externalName += externalNames[i]; - return externalName; - } - } - - externalName += "L" + externalizeClass(baseType) + ";"; - - return externalName; - } - - /** - * list of well known typenames as written in Java code - */ - final static private String[] internalNames = { - "", /* equivalent to void */ - "void", - "byte", - "char", - "short", - "int", - "long", - "float", - "double", - "boolean", - "Byte", - "Character", - "Short", - "Integer", - "Long", - "Float", - "Double", - "String", - "java.lang.Byte", - "java.lang.Character", - "java.lang.Short", - "java.lang.Integer", - "java.lang.Long", - "java.lang.Float", - "java.lang.Double", - "java.lang.String" - }; - - /** - * list of typenames in external form corresponding to entries ni previous list - */ - final static private String[] externalNames = { - "$", - "V", - "B", - "C", - "S", - "I", - "J", - "F", - "D", - "Z", - "Ljava/lang/Byte;", - "Ljava/lang/Character;", - "Ljava/lang/Short;", - "Ljava/lang/Integer;", - "Ljava/lang/Long;", - "Ljava/lang/Float;", - "Ljava/lang/Double;", - "Ljava/lang/String;", - "Ljava/lang/Byte;", - "Ljava/lang/Character;", - "Ljava/lang/Short;", - "Ljava/lang/Integer;", - "Ljava/lang/Long;", - "Ljava/lang/Float;", - "Ljava/lang/Double;", - "Ljava/lang/String;" - }; - - /** - * convert a method descriptor from canonical form to the form used to represent it externally - * - * @param desc the method descriptor which must be trimmed of any surrounding white space - * @return an externalised form for the descriptor - */ - public static String externalizeDescriptor(String desc) - { - // the descriptor will start with '(' and the arguments list should end with ')' and, - // if it is not void be followed by a return type - int openIdx = desc.indexOf('('); - int closeIdx = desc.indexOf(')'); - int length = desc.length(); - if (openIdx != 0) { - return ""; - } - if (closeIdx < 0) { - return ""; - } - String retType = (closeIdx < length ? desc.substring(closeIdx + 1).trim() : ""); - String externalRetType = externalizeType(retType); - String argString = desc.substring(1, closeIdx).trim(); - String externalArgs = ""; - if (argString.equals("")) { - externalArgs = argString; - } else { - String[] args = desc.substring(1, closeIdx).trim().split(","); - for (int i = 0; i < args.length ; i++) { - externalArgs += externalizeType(args[i]); - } - } - - return "(" + externalArgs + ")" + externalRetType; - } - - /** - * convert a method descriptor from the form used to represent it externally to canonical form - * - * @param desc the method descriptor which must be trimmed of any surrounding white space and start with "(". - * it must end either with ")" or with ") " followed by an exernalized return type - * @return an internalised form for the descriptor, possibly followed by a space and externalized return type - */ - public static String internalizeDescriptor(String desc) - { - StringBuffer buffer = new StringBuffer(); - String sepr = ""; - int argStart = desc.indexOf('('); - int argEnd = desc.indexOf(')'); - int max = desc.length(); - if (argStart < 0 || argEnd < 0) { - return "(...)"; - } - int arrayCount = 0; - boolean addSepr = false; - - buffer.append("("); - - for (int idx = argStart + 1; idx < max;) { - char next = desc.charAt(idx); - if (addSepr) { - while (arrayCount > 0) { - buffer.append("[]"); - arrayCount--; - } - buffer.append(sepr); - } - addSepr = true; - switch(next) { - case 'B': - { - buffer.append("byte"); - } - break; - case 'C': - { - buffer.append("char"); - } - break; - case 'S': - { - buffer.append("short"); - } - break; - case 'I': - { - buffer.append("int"); - } - break; - case 'J': - { - buffer.append("long"); - } - break; - case 'Z': - { - buffer.append("boolean"); - } - break; - case 'F': - { - buffer.append("float"); - } - break; - case 'D': - { - buffer.append("double"); - } - case 'V': - { - buffer.append("void"); - } - break; - case 'L': - { - int tailIdx = idx+1; - while (tailIdx < max) { - char tailChar = desc.charAt(tailIdx); - if (tailChar == ';') { - break; - } - if (tailChar == '/') - { - tailChar = '.'; - } - buffer.append(tailChar); - tailIdx++; - } - idx = tailIdx; - } - break; - case '[': - { - arrayCount++; - addSepr = false; - } - break; - case ')': - { - if (idx == argEnd - 1) { - buffer.append(")"); - } else { - // leave room for return type - buffer.append(") "); - } - addSepr = false; - } - break; - default: - { - addSepr = false; - } - } - idx++; - if (idx < argEnd) { - sepr = ","; - } else { - sepr = ""; - } - } - - return buffer.toString(); - } - - /** - * split off the method name preceding the signature and return it - * @param targetMethod - the unqualified method name, possibly including signature - * @return the method name - */ - public static String parseMethodName(String targetMethod) { - int sigIdx = targetMethod.indexOf("("); - if (sigIdx > 0) { - return targetMethod.substring(0, sigIdx).trim(); - } else { - return targetMethod; - } - } - - /** - * split off the signature following the method name and return it - * @param targetMethod - the unqualified method name, possibly including signature - * @return the signature - */ - public static String parseMethodDescriptor(String targetMethod) { - int descIdx = targetMethod.indexOf("("); - if (descIdx >= 0) { - String desc = targetMethod.substring(descIdx, targetMethod.length()).trim(); - return externalizeDescriptor(desc); - } else { - return ""; - } - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArgNamesBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArgNamesBinding.java deleted file mode 100644 index b752daf1c..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArgNamesBinding.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class ArgNamesBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - - String[] parameterNames = bindingContext.getMethodProcessor().getParameterNames(); - - AsmOpUtils.push(instructions, parameterNames.length); - AsmOpUtils.newArray(instructions, AsmOpUtils.STRING_TYPE); - - for(int i = 0; i < parameterNames.length; ++i) { - AsmOpUtils.dup(instructions); - - AsmOpUtils.push(instructions, i); - AsmOpUtils.push(instructions, parameterNames[i]); - - AsmOpUtils.arrayStore(instructions, AsmOpUtils.STRING_TYPE); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.STRING_ARRAY_TYPE; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArgsBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArgsBinding.java deleted file mode 100644 index 21f3bc20b..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArgsBinding.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class ArgsBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - AsmOpUtils.loadArgArray(instructions, bindingContext.getMethodProcessor().getMethodNode()); - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.OBJECT_ARRAY_TYPE; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArrayBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArrayBinding.java deleted file mode 100644 index 363ef8928..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ArrayBinding.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * TODO 这个判断是否要从stack上取数据,要看 其它的binding是否需要。 是否 optional,这个应该是由 ArrayBinding 整体设定?? - * @author hengyunabc - * - */ -public class ArrayBinding extends Binding{ - - // TODO 数组的 type是什么? -// private Type type; - - List bindingList = new ArrayList(); - - public ArrayBinding(List bindingList) { - this.bindingList = bindingList; - } - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - AsmOpUtils.push(instructions, bindingList.size()); - AsmOpUtils.newArray(instructions, AsmOpUtils.OBJECT_TYPE); - - for(int i = 0; i < bindingList.size(); ++i) { - AsmOpUtils.dup(instructions); - - AsmOpUtils.push(instructions, i); - Binding binding = bindingList.get(i); - binding.pushOntoStack(instructions, bindingContext); - AsmOpUtils.box(instructions, binding.getType(bindingContext)); - - AsmOpUtils.arrayStore(instructions, AsmOpUtils.OBJECT_TYPE); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/Binding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/Binding.java deleted file mode 100644 index 24b99cdef..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/Binding.java +++ /dev/null @@ -1,424 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.asm.binding.annotation.BindingParser; -import com.taobao.arthas.bytekit.asm.binding.annotation.BindingParserHandler; - - -public abstract class Binding { - - /** - * 是否可选的,当不符合条件,或者获取不到值时,会转为 null,这个不支持原始类型,就像java.util.Optional 一样? - * @return - */ - public boolean optional() { - return false; - } - - /** - * 检查当前条件下这个binding是否可以工作,比如检查field是否有这个field。 - * @return - */ - public boolean check(BindingContext bindingContext) { - return true; - } - - /** - * 把这个binding本身放到栈上 - * @param instructions - * @param bindingContext - */ - public abstract void pushOntoStack(InsnList instructions, BindingContext bindingContext); - - public abstract Type getType( BindingContext bindingContext); - - public boolean fromStack() { - return false; - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = ArgsBindingParser.class) - public static @interface Args { - - boolean optional() default false; - - } - public static class ArgsBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new ArgsBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = ArgNamesBindingParser.class) - public static @interface ArgNames { - - boolean optional() default false; - - } - public static class ArgNamesBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new ArgNamesBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = LocalVarsBindingParser.class) - public static @interface LocalVars { - - boolean optional() default false; - - } - public static class LocalVarsBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new LocalVarsBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = LocalVarNamesBindingParser.class) - public static @interface LocalVarNames { - - boolean optional() default false; - - } - public static class LocalVarNamesBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new LocalVarNamesBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = ClassBindingParser.class) - public static @interface Class { - - boolean optional() default false; - - } - - public static class ClassBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new ClassBinding(); - } - - } - - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = FieldBindingParser.class) - public static @interface Field { - boolean optional() default false; - java.lang.Class owner() default Void.class; - java.lang.Class type() default Void.class; - String name(); - boolean isStatic() default false; - boolean box() default false; - } - - public static class FieldBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - Field field = (Field) annotation; - Type ownerType = Type.getType(field.owner()); - if(field.owner().equals(Void.class)) { - ownerType = null; - } - Type fieldType = Type.getType(field.type()); - if(field.type().equals(Void.class)) { - fieldType = null; - } - return new FieldBinding(ownerType, field.name(), fieldType, - field.isStatic(), field.box()); - } - } - - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = InvokeArgsBindingParser.class) - public static @interface InvokeArgs { - - boolean optional() default false; - - } - - public static class InvokeArgsBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new InvokeArgsBinding(); - } - } - - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = InvokeReturnBindingParser.class) - public static @interface InvokeReturn { - - boolean optional() default false; - - } - - public static class InvokeReturnBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new InvokeReturnBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = InvokeMethodNameBindingParser.class) - public static @interface InvokeMethodName { - - boolean optional() default false; - - } - - public static class InvokeMethodNameBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new InvokeMethodNameBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = InvokeMethodOwnerBindingParser.class) - public static @interface InvokeMethodOwner { - - boolean optional() default false; - - } - - public static class InvokeMethodOwnerBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new InvokeMethodOwnerBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = InvokeMethodDeclarationBindingParser.class) - public static @interface InvokeMethodDeclaration { - - boolean optional() default false; - - } - - public static class InvokeMethodDeclarationBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new InvokeMethodDeclarationBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = InvokeInfoBindingParser.class) - public static @interface InvokeInfo { - - boolean optional() default false; - - } - - public static class InvokeInfoBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new InvokeInfoBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = MethodBindingParser.class) - public static @interface Method { - boolean optional() default false; - } - - public static class MethodBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new MethodBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = MethodNameBindingParser.class) - public static @interface MethodName { - boolean optional() default false; - } - - public static class MethodNameBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new MethodNameBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = MethodDescBindingParser.class) - public static @interface MethodDesc { - boolean optional() default false; - } - - public static class MethodDescBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new MethodDeclarationBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = MethodInfoBindingParser.class) - public static @interface MethodInfo { - boolean optional() default false; - } - - public static class MethodInfoBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new MethodInfoBinding(); - } - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = ReturnBindingParser.class) - public static @interface Return { - - boolean optional() default false; - - } - - public static class ReturnBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new ReturnBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = ThisBindingParser.class) - public static @interface This { - - } - - public static class ThisBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new ThisBinding(); - } - - } - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = ThrowableBindingParser.class) - public static @interface Throwable { - - boolean optional() default false; - - } - - public static class ThrowableBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new ThrowableBinding(); - } - - } - - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = LineBindingParser.class) - public static @interface Line { - boolean optional() default false; - - /** - * 是否精确是在某个 LineNumberNode 上。如果为true的话,会向上找到最接近的 LineNumberNode - * - * @return - */ - boolean exact() default false; - - } - - public static class LineBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - Line line = (Line) annotation; - return new LineBinding(line.exact()); - } - } - - - @Documented - @Retention(RetentionPolicy.RUNTIME) - @java.lang.annotation.Target(ElementType.PARAMETER) - @BindingParserHandler(parser = MonitorBindingParser.class) - public static @interface Monitor { - - boolean optional() default false; - - } - - public static class MonitorBindingParser implements BindingParser { - @Override - public Binding parse(Annotation annotation) { - return new MonitorBinding(); - } - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/BindingContext.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/BindingContext.java deleted file mode 100644 index 2fcfb3bed..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/BindingContext.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location; - -public class BindingContext { - private MethodProcessor methodProcessor; - private Location location; - private StackSaver stackSaver; - - public BindingContext(Location location, MethodProcessor methodProcessor, StackSaver stackSaver) { - this.location = location; - this.methodProcessor = methodProcessor; - this.stackSaver = stackSaver; - } - - public MethodProcessor getMethodProcessor() { - return methodProcessor; - } - - public void setMethodProcessor(MethodProcessor methodProcessor) { - this.methodProcessor = methodProcessor; - } - - public Location getLocation() { - return location; - } - - public void setLocation(Location location) { - this.location = location; - } - - public StackSaver getStackSaver() { - return stackSaver; - } - - public void setStackSaver(StackSaver stackSaver) { - this.stackSaver = stackSaver; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ClassBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ClassBinding.java deleted file mode 100644 index 360afcf75..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ClassBinding.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class ClassBinding extends Binding{ - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - String owner = bindingContext.getMethodProcessor().getOwner(); - AsmOpUtils.ldc(instructions, Type.getObjectType(owner)); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(Class.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/FieldBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/FieldBinding.java deleted file mode 100644 index 9c20b2664..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/FieldBinding.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FieldNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; - -public class FieldBinding extends Binding { - /** - * maybe null - */ - private Type owner; - - private boolean box = false; - - private String name; - - private boolean isStatic = false; - - /** - * maybe null - */ - private Type type; - - public FieldBinding(Type owner, String name, Type type, boolean isStatic, boolean box) { - this.owner = owner; - this.name = name; - this.isStatic = isStatic; - this.box = box; - this.type = type; - } - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Type onwerType = owner; - Type fieldType = type; - boolean fieldIsStatic = isStatic; - if (owner == null) { - onwerType = Type.getObjectType(bindingContext.getMethodProcessor().getOwner()); - } - // 当type是null里,需要从ClassNode里查找到files,确定type - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - if (fieldType == null) { - ClassNode classNode = methodProcessor.getClassNode(); - if (classNode == null) { - throw new IllegalArgumentException( - "classNode is null, cann not get owner type. FieldBinding name:" + name); - } - FieldNode field = AsmUtils.findField(classNode.fields, name); - if (field == null) { - throw new IllegalArgumentException("can not find field in ClassNode. FieldBinding name:" + name); - } - fieldType = Type.getType(field.desc); - if ((field.access & Opcodes.ACC_STATIC) != 0) { - fieldIsStatic = true; - }else { - fieldIsStatic = false; - } - } - - if (fieldIsStatic) { - AsmOpUtils.getStatic(instructions, onwerType, name, fieldType); - } else { - methodProcessor.loadThis(instructions); - AsmOpUtils.getField(instructions, onwerType, name, fieldType); - } - if (box) { - AsmOpUtils.box(instructions, fieldType); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - Type fieldType = type; - if (fieldType == null) { - ClassNode classNode = bindingContext.getMethodProcessor().getClassNode(); - if (classNode == null) { - throw new IllegalArgumentException( - "classNode is null, cann not get owner type. FieldBinding name:" + name); - } - FieldNode field = AsmUtils.findField(classNode.fields, name); - if (field == null) { - throw new IllegalArgumentException("can not find field in ClassNode. FieldBinding name:" + name); - } - fieldType = Type.getType(field.desc); - } - return fieldType; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/IntBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/IntBinding.java deleted file mode 100644 index 7400da633..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/IntBinding.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class IntBinding extends Binding { - - private int value; - - private boolean box = true; - - public IntBinding(int value) { - this(value, true); - } - - public IntBinding(int value, boolean box) { - this.value = value; - this.box = box; - } - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - AsmOpUtils.push(instructions, value); - if (box) { - AsmOpUtils.box(instructions, Type.INT_TYPE); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.INT_TYPE; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeArgsBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeArgsBinding.java deleted file mode 100644 index 4561a0e12..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeArgsBinding.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; - -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.asm.location.Location.InvokeLocation; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * invoke 传入的参数列表,有严格的限制,只能在 invoke 之前。 - * - * TODO ,当 static 函数时,在数组前,传一个null进去? 不然,不好区分是否 static 函数调用?? - * - * @author hengyunabc - * - */ -public class InvokeArgsBinding extends Binding { - - @Override - public boolean fromStack() { - return true; - } - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - - if(location instanceof InvokeLocation) { - InvokeLocation invokeLocation = (InvokeLocation) location; - if(invokeLocation.isWhenComplete()) { - throw new IllegalArgumentException("InvokeArgsBinding can not work on InvokeLocation whenComplete is true."); - } - }else { - throw new IllegalArgumentException("current location is not invoke location. location: " + location); - } - - LocalVariableNode invokeArgsVariableNode = bindingContext.getMethodProcessor().initInvokeArgsVariableNode(); - AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_ARRAY_TYPE, invokeArgsVariableNode.index); - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.OBJECT_ARRAY_TYPE; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeInfoBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeInfoBinding.java deleted file mode 100644 index 36e550160..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeInfoBinding.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LineNumberNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.taobao.arthas.bytekit.asm.location.MethodInsnNodeWare; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * 包含 owner/method name/ method desc/ line number - * - * @author hengyunabc 2020-05-14 - * - */ -public class InvokeInfoBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - if (location instanceof MethodInsnNodeWare) { - MethodInsnNodeWare methodInsnNodeWare = (MethodInsnNodeWare) location; - MethodInsnNode methodInsnNode = methodInsnNodeWare.methodInsnNode(); - - int line = -1; - - if (location.isWhenComplete() == false) { - AbstractInsnNode insnNode = methodInsnNode.getPrevious(); - while (insnNode != null) { - if (insnNode instanceof LineNumberNode) { - line = ((LineNumberNode) insnNode).line; - break; - } - insnNode = insnNode.getPrevious(); - } - } else { - AbstractInsnNode insnNode = methodInsnNode.getNext(); - while (insnNode != null) { - if (insnNode instanceof LineNumberNode) { - line = ((LineNumberNode) insnNode).line; - break; - } - insnNode = insnNode.getNext(); - } - } - - String result = methodInsnNode.owner + "|" + methodInsnNode.name + "|" + methodInsnNode.desc + "|" + line; - AsmOpUtils.push(instructions, result); - - } else { - throw new IllegalArgumentException( - "InvokeMethodNameBinding location is not Invocation location, location: " + location); - } - - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodDeclarationBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodDeclarationBinding.java deleted file mode 100644 index 2c802068a..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodDeclarationBinding.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.taobao.arthas.bytekit.asm.location.MethodInsnNodeWare; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * - * @author hengyunabc - * - */ -public class InvokeMethodDeclarationBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - if (location instanceof MethodInsnNodeWare) { - MethodInsnNodeWare methodInsnNodeWare = (MethodInsnNodeWare) location; - MethodInsnNode methodInsnNode = methodInsnNodeWare.methodInsnNode(); - AsmOpUtils.push(instructions, methodInsnNode.desc); - - } else { - throw new IllegalArgumentException( - "InvokeMethodDeclarationBinding location is not Invocation location, location: " + location); - } - - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodNameBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodNameBinding.java deleted file mode 100644 index 581bb0646..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodNameBinding.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.taobao.arthas.bytekit.asm.location.MethodInsnNodeWare; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * - * @author hengyunabc - * - */ -public class InvokeMethodNameBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - if (location instanceof MethodInsnNodeWare) { - MethodInsnNodeWare methodInsnNodeWare = (MethodInsnNodeWare) location; - MethodInsnNode methodInsnNode = methodInsnNodeWare.methodInsnNode(); - AsmOpUtils.push(instructions, methodInsnNode.name); - - } else { - throw new IllegalArgumentException( - "InvokeMethodNameBinding location is not Invocation location, location: " + location); - } - - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodOwnerBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodOwnerBinding.java deleted file mode 100644 index 9a962d4bc..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeMethodOwnerBinding.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.taobao.arthas.bytekit.asm.location.MethodInsnNodeWare; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * - * @author hengyunabc 2020-05-02 - * - */ -public class InvokeMethodOwnerBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - if (location instanceof MethodInsnNodeWare) { - MethodInsnNodeWare methodInsnNodeWare = (MethodInsnNodeWare) location; - MethodInsnNode methodInsnNode = methodInsnNodeWare.methodInsnNode(); - AsmOpUtils.push(instructions, methodInsnNode.owner); - - } else { - throw new IllegalArgumentException( - "InvokeMethodOwnerBinding location is not Invocation location, location: " + location); - } - - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeReturnBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeReturnBinding.java deleted file mode 100644 index d36d786c5..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/InvokeReturnBinding.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; - -/** - * invoke 的返回值 - * @author hengyunabc - * - */ -public class InvokeReturnBinding extends Binding { - - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - AbstractInsnNode insnNode = bindingContext.getLocation().getInsnNode(); - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - String uniqueNameForMethod = AsmUtils.uniqueNameForMethod(methodInsnNode.owner, methodInsnNode.name, - methodInsnNode.desc); - Type invokeReturnType = Type.getMethodType(methodInsnNode.desc).getReturnType(); - if(invokeReturnType.equals(Type.VOID_TYPE)) { - AsmOpUtils.push(instructions, null); - }else { - LocalVariableNode invokeReturnVariableNode = methodProcessor.initInvokeReturnVariableNode( - uniqueNameForMethod, Type.getMethodType(methodInsnNode.desc).getReturnType()); - AsmOpUtils.loadVar(instructions, invokeReturnType, invokeReturnVariableNode.index); - } - } else { - throw new IllegalArgumentException( - "InvokeReturnBinding location is not MethodInsnNode, insnNode: " + insnNode); - } - - } - - @Override - public boolean fromStack() { - return true; - } - - @Override - public Type getType(BindingContext bindingContext) { - AbstractInsnNode insnNode = bindingContext.getLocation().getInsnNode(); - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - Type invokeReturnType = Type.getMethodType(methodInsnNode.desc).getReturnType(); - return invokeReturnType; - } else { - throw new IllegalArgumentException( - "InvokeReturnBinding location is not MethodInsnNode, insnNode: " + insnNode); - } - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LineBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LineBinding.java deleted file mode 100644 index 7c1e80073..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LineBinding.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LineNumberNode; - -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * - * @author hengyunabc - * - */ -public class LineBinding extends Binding { - - private boolean exact; - - public LineBinding(boolean exact) { - this.exact = exact; - } - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - AbstractInsnNode insnNode = location.getInsnNode(); - - int line = -1; - if (exact) { - if (insnNode instanceof LineNumberNode) { - line = ((LineNumberNode) insnNode).line; - } else { - throw new IllegalArgumentException("LineBinding location is not LineNumberNode, insnNode: " + insnNode); - } - } else { - if (location.isWhenComplete() == false) { - while (insnNode != null) { - if (insnNode instanceof LineNumberNode) { - line = ((LineNumberNode) insnNode).line; - break; - } - insnNode = insnNode.getPrevious(); - } - } else { - while (insnNode != null) { - if (insnNode instanceof LineNumberNode) { - line = ((LineNumberNode) insnNode).line; - break; - } - insnNode = insnNode.getNext(); - } - } - } - AsmOpUtils.push(instructions, line); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(int.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LocalVarNamesBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LocalVarNamesBinding.java deleted file mode 100644 index 56bffb23e..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LocalVarNamesBinding.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class LocalVarNamesBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - AbstractInsnNode currentInsnNode = bindingContext.getLocation().getInsnNode(); - List results = AsmOpUtils - .validVariables(bindingContext.getMethodProcessor().getMethodNode().localVariables, currentInsnNode); - - AsmOpUtils.push(instructions, results.size()); - AsmOpUtils.newArray(instructions, AsmOpUtils.STRING_TYPE); - - for (int i = 0; i < results.size(); ++i) { - AsmOpUtils.dup(instructions); - - AsmOpUtils.push(instructions, i); - AsmOpUtils.push(instructions, results.get(i).name); - - AsmOpUtils.arrayStore(instructions, AsmOpUtils.STRING_TYPE); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.STRING_ARRAY_TYPE; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LocalVarsBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LocalVarsBinding.java deleted file mode 100644 index 7f1ccac86..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/LocalVarsBinding.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; - -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * TODO 增加一个配置,是否包含 method args - * @author hengyunabc - * - */ -public class LocalVarsBinding extends Binding{ - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - - AbstractInsnNode currentInsnNode = bindingContext.getLocation().getInsnNode(); - - List results = AsmOpUtils - .validVariables(bindingContext.getMethodProcessor().getMethodNode().localVariables, currentInsnNode); - - AsmOpUtils.push(instructions, results.size()); - AsmOpUtils.newArray(instructions, AsmOpUtils.OBJECT_TYPE); - - for (int i = 0; i < results.size(); ++i) { - AsmOpUtils.dup(instructions); - - AsmOpUtils.push(instructions, i); - - LocalVariableNode variableNode = results.get(i); - AsmOpUtils.loadVar(instructions, Type.getType(variableNode.desc), variableNode.index); - AsmOpUtils.box(instructions, Type.getType(variableNode.desc)); - - AsmOpUtils.arrayStore(instructions, AsmOpUtils.OBJECT_TYPE); - } - - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.OBJECT_ARRAY_TYPE; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodBinding.java deleted file mode 100644 index d3ba3c785..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodBinding.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * @author hengyunabc - * - */ -public class MethodBinding extends Binding{ - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - // 先获取类本身的 class ,再调用 getDeclaredMethod ,它需要一个变长参数,实际上要传一个数组 - /** - * @see java.lang.Class.getDeclaredMethod(String, Class...) - */ - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - AsmOpUtils.ldc(instructions, Type.getObjectType(methodProcessor.getOwner())); - - AsmOpUtils.push(instructions, methodProcessor.getMethodNode().name); - - Type[] argumentTypes = Type.getMethodType(methodProcessor.getMethodNode().desc).getArgumentTypes(); - - AsmOpUtils.push(instructions, argumentTypes.length); - AsmOpUtils.newArray(instructions, Type.getType(Class.class)); - - for(int i = 0; i < argumentTypes.length; ++i) { - AsmOpUtils.dup(instructions); - - AsmOpUtils.push(instructions, i); - - AsmOpUtils.ldc(instructions, argumentTypes[i]); - AsmOpUtils.arrayStore(instructions, Type.getType(Class.class)); - } - - MethodInsnNode declaredMethodInsnNode = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getType(Class.class).getInternalName(), - "getDeclaredMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;", false); - instructions.add(declaredMethodInsnNode); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(java.lang.reflect.Method.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodDeclarationBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodDeclarationBinding.java deleted file mode 100644 index bd9d442e3..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodDeclarationBinding.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * TODO 提供一个完整的 method 的string,包含类名,并不是desc?用户可以自己提取descs method的定义,前面是 public - * /static 这些关键字,是有限的几个。后面是 throws ,的异常信息。 或者做一下取巧比如把 classname | methoname | desc 之类连起一个String - * - * @author hengyunabc - * - */ -public class MethodDeclarationBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); -// AsmOpUtils.ldc(instructions, AsmUtils.methodDeclaration(Type.getObjectType(methodProcessor.getOwner()), -// methodProcessor.getMethodNode())); - AsmOpUtils.ldc(instructions, methodProcessor.getMethodNode().desc); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodInfoBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodInfoBinding.java deleted file mode 100644 index 849bf661f..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodInfoBinding.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * method name | method desc 的方式组织 - * - * TODO 是否要有 line number ? - * - * @author hengyunabc 2020-05-16 - * - */ -public class MethodInfoBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - MethodNode methodNode = methodProcessor.getMethodNode(); - AsmOpUtils.ldc(instructions, methodNode.name + '|' + methodNode.desc); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodNameBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodNameBinding.java deleted file mode 100644 index 148d5178f..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MethodNameBinding.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -/** - * @author hengyunabc - * - */ -public class MethodNameBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - AsmOpUtils.ldc(instructions, methodProcessor.getMethodNode().name); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(String.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MonitorBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MonitorBinding.java deleted file mode 100644 index 8dcffb6e8..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/MonitorBinding.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; - -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.asm.location.Location.SyncEnterLocation; -import com.taobao.arthas.bytekit.asm.location.Location.SyncExitLocation; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class MonitorBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - Location location = bindingContext.getLocation(); - - if (location.isWhenComplete()) { - throw new IllegalArgumentException("MonitorBinding only support location whenComplete is false."); - } - - if (location instanceof SyncEnterLocation || location instanceof SyncExitLocation) { - LocalVariableNode monitorVariableNode = bindingContext.getMethodProcessor().initMonitorVariableNode(); - AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_TYPE, monitorVariableNode.index); - } else { - throw new IllegalArgumentException( - "MonitorBinding only support SyncEnterLocation or SyncExitLocation. location: " + location); - } - } - - @Override - public boolean fromStack() { - return true; - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.OBJECT_TYPE; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ReturnBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ReturnBinding.java deleted file mode 100644 index 66c959ba5..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ReturnBinding.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; - -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; - -public class ReturnBinding extends Binding { - - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - //check location - - Location location = bindingContext.getLocation(); - - if (!AsmOpUtils.isReturnCode(location.getInsnNode().getOpcode())) { - throw new IllegalArgumentException("current location is not return location. location: " + location); - } - - Type returnType = bindingContext.getMethodProcessor().getReturnType(); - if(returnType.equals(Type.VOID_TYPE)) { - AsmOpUtils.push(instructions, null); - }else { - LocalVariableNode returnVariableNode = bindingContext.getMethodProcessor().initReturnVariableNode(); - AsmOpUtils.loadVar(instructions, returnType, returnVariableNode.index); - } - - } - - @Override - public boolean fromStack() { - return true; - } - - @Override - public Type getType(BindingContext bindingContext) { - return bindingContext.getMethodProcessor().getReturnType(); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/StackSaver.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/StackSaver.java deleted file mode 100644 index 2f5b22aa1..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/StackSaver.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -/** - * 在 return/throw/invoke 等location时,需要把栈上的值保存到locals里 - * @author hengyunabc - * - */ -public interface StackSaver { - /** - * 有可能在两个地方被调用。1: 在最开始保存栈上的值时, 2: callback函数有返回值,想更新这个值时。stackSaver自己内部要保证保存的locals index是一致的 - * @param instructions - * @param bindingContext - */ - public void store(InsnList instructions, BindingContext bindingContext); - - public void load(InsnList instructions, BindingContext bindingContext); - - public Type getType(BindingContext bindingContext); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ThisBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ThisBinding.java deleted file mode 100644 index 1e90140a4..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ThisBinding.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -public class ThisBinding extends Binding { - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - bindingContext.getMethodProcessor().loadThis(instructions); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(Object.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ThrowableBinding.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ThrowableBinding.java deleted file mode 100644 index f05f5399d..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/ThrowableBinding.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; - -/** - * TODO 要检查 location 是否是合法的 - * @author hengyunabc - * - */ -public class ThrowableBinding extends Binding { - - @Override - public boolean fromStack() { - return true; - } - - @Override - public void pushOntoStack(InsnList instructions, BindingContext bindingContext) { - // TODO 这里从 StackSaver 里取是否合理? - bindingContext.getStackSaver().load(instructions, bindingContext); - // 是否要 check cast ? - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(Throwable.class); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/annotation/BindingParser.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/annotation/BindingParser.java deleted file mode 100644 index c507e3846..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/annotation/BindingParser.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding.annotation; - -import java.lang.annotation.Annotation; - -import com.taobao.arthas.bytekit.asm.binding.Binding; - -public interface BindingParser { - - public Binding parse(Annotation annotation); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/annotation/BindingParserHandler.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/annotation/BindingParserHandler.java deleted file mode 100644 index b898f6002..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/binding/annotation/BindingParserHandler.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.taobao.arthas.bytekit.asm.binding.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.ANNOTATION_TYPE) -public @interface BindingParserHandler { - - Class parser(); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/Instrument.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/Instrument.java deleted file mode 100644 index 1dc51dba6..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/Instrument.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - - -/** - * 在这里支持配置一个 error hander ?做为插入的异常处理的 - * - * 按名字匹配,按模糊匹配??有没有这样子的需求?,按interface匹配,按基础类继承的匹配 - * - * 函数的匹配,直接是名字一样,desc 一样的。 匹配有 annotation 的 - * - * 只有 NewField 才是加新的field,原来类里有的field,就直接写上就可以了。 - * @author hengyunabc - * - */ -@Target({ java.lang.annotation.ElementType.TYPE }) -@Retention(RetentionPolicy.RUNTIME) -public @interface Instrument { -// Instrumentation -// MatchType type() default MatchType.ExactClass; - - String[] Class() default {}; - String[] BaseClass() default {}; - String[] Interface() default {}; - - String originalName() default ""; - - Class suppress() default Throwable.class; - - Class suppressHandler() default Void.class; -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/InstrumentApi.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/InstrumentApi.java deleted file mode 100644 index d9e48a5db..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/InstrumentApi.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - - -/** - * - *
- * 实现这个 invokeOrigin(),需要多步处理:
- *
- * 传入要被替换的类,读取到标记了 @Instrument 的类。 类名不一样的话,先替换类名?
- *
- * 然后查找所有的 field,如果有标记了 @NewField ,则增加到要被替换的类里。
- *
- * 然后查找所有的函数, 再查找是否在 旧类里有同样签名的,如果有,则执行清除行号, 替换 invokeOrigin() ,再 inline 原来的旧函数
- *
- * 再替换函数到 旧类里。
- *
- * 类名有可能要替换
- *
- * 
- * - * - * - * - * - * @author hengyunabc 2019-02-25 - * - */ -public class InstrumentApi { - public static final T invokeOrigin() { - return null; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/NewField.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/NewField.java deleted file mode 100644 index 3e0707a04..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/NewField.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ java.lang.annotation.ElementType.FIELD }) -@Retention(RetentionPolicy.RUNTIME) -public @interface NewField { -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/impl/InstrumentImpl.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/impl/InstrumentImpl.java deleted file mode 100644 index 977a42050..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/impl/InstrumentImpl.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst.impl; - -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.Method; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TypeInsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; - -/** - * - * @author hengyunabc 2019-03-15 - * - */ -public class InstrumentImpl { - - public static MethodNode replaceInvokeOrigin(String originOwner, MethodNode originMethodNode, - MethodNode apmMethodNode) { - - // 查找到所有的 InstrumentApi.invokeOrigin() 指令 - List methodInsnNodes = AsmUtils.findMethodInsnNode(apmMethodNode, - "com/taobao/arthas/bytekit/asm/inst/InstrumentApi", "invokeOrigin", "()Ljava/lang/Object;"); - - Type originReturnType = Type.getMethodType(originMethodNode.desc).getReturnType(); - - for (MethodInsnNode methodInsnNode : methodInsnNodes) { - InsnList instructions = new InsnList(); - - AbstractInsnNode secondInsnNode = methodInsnNode.getNext(); - - // 如果是 非 static ,则要 load this - boolean isStatic = AsmUtils.isStatic(originMethodNode); - int opcode = isStatic ? Opcodes.INVOKESTATIC : Opcodes.INVOKEVIRTUAL; - if (!isStatic) { - AsmOpUtils.loadThis(instructions); - } - AsmOpUtils.loadArgs(instructions, originMethodNode); - - MethodInsnNode originMethodInsnNode = new MethodInsnNode(opcode, originOwner, originMethodNode.name, - originMethodNode.desc, false); - // 调用原来的函数 - instructions.add(originMethodInsnNode); - - int sort = originReturnType.getSort(); - if (sort == Type.VOID) { - if (secondInsnNode != null) { - if (secondInsnNode.getOpcode() == Opcodes.POP) { - // TODO 原来的函数没有返回值,这里要把 POP去掉。有没有可能是 POP2 ? - apmMethodNode.instructions.remove(secondInsnNode); - } else { - // TODO 原来函数没有返回值,这里有没有可能要赋值??是否要 push null? - AsmOpUtils.pushNUll(instructions); - } - } - } else if (sort >= Type.BOOLEAN && sort <= Type.DOUBLE) { - if (secondInsnNode.getOpcode() == Opcodes.POP) { - // 原来是 pop掉一个栈,如果函数返回的是 long,则要pop2 - if (originReturnType.getSize() == 2) { - apmMethodNode.instructions.insert(secondInsnNode, new InsnNode(Opcodes.POP2)); - apmMethodNode.instructions.remove(secondInsnNode); - } - } else { - /** - * 需要把下面两条cast和unbox的指令删掉 - * - *
-                     * CHECKCAST java/lang/Integer
-                     * INVOKEVIRTUAL java/lang/Integer.intValue ()I
-                     * 
- */ - boolean removeCheckCast = false; - if (secondInsnNode.getOpcode() == Opcodes.CHECKCAST) { - TypeInsnNode typeInsnNode = (TypeInsnNode) secondInsnNode; - // 从原始函数的返回值,获取到它对应的自动box的类 - Type boxedType = AsmOpUtils.getBoxedType(originReturnType); - if (Type.getObjectType(typeInsnNode.desc).equals(boxedType)) { - AbstractInsnNode thridInsnNode = secondInsnNode.getNext(); - if (thridInsnNode != null && thridInsnNode.getOpcode() == Opcodes.INVOKEVIRTUAL) { - MethodInsnNode valueInsnNode = (MethodInsnNode) thridInsnNode; - Method unBoxMethod = AsmOpUtils.getUnBoxMethod(originReturnType); - if (unBoxMethod.getDescriptor().equals(valueInsnNode.desc) - && valueInsnNode.owner.equals(boxedType.getInternalName())) { - apmMethodNode.instructions.remove(thridInsnNode); - apmMethodNode.instructions.remove(secondInsnNode); - removeCheckCast = true; - } - } - } - } - if (!removeCheckCast) { - // 没有被转换为原始类型,也没有pop,则说明赋值给了一个对象,用类似Long.valudOf转换为Object - AsmOpUtils.box(instructions, originReturnType); - - } - - } - } else {// ARRAY/OBJECT - // 移掉可能有的 check cast - if (secondInsnNode.getOpcode() == Opcodes.CHECKCAST) { - TypeInsnNode typeInsnNode = (TypeInsnNode) secondInsnNode; - if (Type.getObjectType(typeInsnNode.desc).equals(originReturnType)) { - apmMethodNode.instructions.remove(secondInsnNode); - } - } - } - apmMethodNode.instructions.insertBefore(methodInsnNode, instructions); - apmMethodNode.instructions.remove(methodInsnNode); - } - - MethodProcessor methodProcessor = new MethodProcessor(originOwner, apmMethodNode); - methodProcessor.inline(originOwner, originMethodNode); - - return apmMethodNode; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/impl/MethodReplaceResult.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/impl/MethodReplaceResult.java deleted file mode 100644 index b45d22eba..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/inst/impl/MethodReplaceResult.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst.impl; - -import com.alibaba.arthas.deps.org.objectweb.asm.Label; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -/** - * - * @author hengyunabc 2019-03-18 - * - */ -public class MethodReplaceResult { - - private boolean success; - - private Label start; - private Label end; - - private MethodNode methodNode; - - public Label getStart() { - return start; - } - - public void setStart(Label start) { - this.start = start; - } - - public Label getEnd() { - return end; - } - - public void setEnd(Label end) { - this.end = end; - } - - public MethodNode getMethodNode() { - return methodNode; - } - - public void setMethodNode(MethodNode methodNode) { - this.methodNode = methodNode; - } - - public boolean isSuccess() { - return success; - } - - public void setSuccess(boolean success) { - this.success = success; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/EnterInteceptor.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/EnterInteceptor.java deleted file mode 100644 index 5ff6fc0f6..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/EnterInteceptor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -public class EnterInteceptor { - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/ExceptionInterceptor.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/ExceptionInterceptor.java deleted file mode 100644 index 9c44d2bf1..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/ExceptionInterceptor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -public class ExceptionInterceptor { - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/ExitInterceptor.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/ExitInterceptor.java deleted file mode 100644 index 894cf1996..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/ExitInterceptor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -public class ExitInterceptor { - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/Inteceptor.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/Inteceptor.java deleted file mode 100644 index ac690943b..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/Inteceptor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -public interface Inteceptor { - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/InterceptorMethodConfig.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/InterceptorMethodConfig.java deleted file mode 100644 index 33fba23e0..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/InterceptorMethodConfig.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import java.util.List; - -import com.taobao.arthas.bytekit.asm.binding.Binding; - -public class InterceptorMethodConfig { - - private boolean inline; - - private String owner; - - private String methodName; - - private String methodDesc; - - private List bindings; - - /** - * 插入的代码用 try/catch 包围的异常类型 - */ - private String suppress; - - public boolean isInline() { - return inline; - } - - public void setInline(boolean inline) { - this.inline = inline; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public String getMethodName() { - return methodName; - } - - public void setMethodName(String methodName) { - this.methodName = methodName; - } - - public String getMethodDesc() { - return methodDesc; - } - - public void setMethodDesc(String methodDesc) { - this.methodDesc = methodDesc; - } - - public List getBindings() { - return bindings; - } - - public void setBindings(List bindings) { - this.bindings = bindings; - } - - public String getSuppress() { - return suppress; - } - - public void setSuppress(String suppress) { - this.suppress = suppress; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/InterceptorProcessor.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/InterceptorProcessor.java deleted file mode 100644 index 739d9eb79..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/InterceptorProcessor.java +++ /dev/null @@ -1,255 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.JumpInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.TryCatchBlock; -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.binding.BindingContext; -import com.taobao.arthas.bytekit.asm.binding.StackSaver; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class InterceptorProcessor { - - private LocationMatcher locationMatcher; - - /** - * 插入的回调函数的配置 - */ - private InterceptorMethodConfig interceptorMethodConfig; - - /** - * 插入的代码被 try/catch 包围的配置,注意有一些location插入try/catch会可能失败,因为不能确切知道栈上的情况 - */ - private InterceptorMethodConfig exceptionHandlerConfig; - - /** - * 加载inlne类所需要的ClassLoader - */ - private ClassLoader classLoader; - - public InterceptorProcessor(ClassLoader classLoader) { - this.classLoader = classLoader; - } - - public List process(MethodProcessor methodProcessor) throws Exception { - List locations = locationMatcher.match(methodProcessor); - - List interceptorBindings = interceptorMethodConfig.getBindings(); - - for (Location location : locations) { - - // 有三小段代码,1: 保存当前栈上的值的 , 2: 插入的回调的 , 3:恢复当前栈的 - - InsnList toInsert = new InsnList(); - - InsnList stackSaveInsnList = new InsnList(); - InsnList stackLoadInsnList = new InsnList(); - - StackSaver stackSaver = null; - if(location.isStackNeedSave()) { - stackSaver = location.getStackSaver(); - } - BindingContext bindingContext = new BindingContext(location, methodProcessor, stackSaver); - - if(stackSaver != null) { - stackSaver.store(stackSaveInsnList, bindingContext); - stackSaver.load(stackLoadInsnList, bindingContext); - } - - - Type methodType = Type.getMethodType(interceptorMethodConfig.getMethodDesc()); - Type[] argumentTypes = methodType.getArgumentTypes(); - // 检查回调函数的参数和 binding数一致 - if(interceptorBindings.size() != argumentTypes.length) { - throw new IllegalArgumentException("interceptorBindings size no equals with interceptorMethod args size."); - } - - // 把当前栈上的数据保存起来 - int fromStackBindingCount = 0; - for (Binding binding : interceptorBindings) { - if(binding.fromStack()) { - fromStackBindingCount++; - } - } - // 只允许一个binding从栈上保存数据 - if(fromStackBindingCount > 1) { - throw new IllegalArgumentException("interceptorBindings have more than one from stack Binding."); - } - - - // 组装好要调用的 static 函数的参数 - for(int i = 0 ; i < argumentTypes.length; ++i) { - Binding binding = interceptorBindings.get(i); - binding.pushOntoStack(toInsert, bindingContext); - // 检查 回调函数的参数类型,看是否要box一下 ,检查是否原始类型就可以了。 - // 只有类型不一样时,才需要判断。比如两个都是 long,则不用判断 - Type bindingType = binding.getType(bindingContext); - if(!bindingType.equals(argumentTypes[i])) { - if(AsmOpUtils.needBox(bindingType)) { - AsmOpUtils.box(toInsert, binding.getType(bindingContext)); - } - } - } - - // TODO 要检查 binding 和 回调的函数的参数类型是否一致。回调函数的类型可以是 Object,或者super。但是不允许一些明显的类型问题,比如array转到int - - toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, interceptorMethodConfig.getOwner(), interceptorMethodConfig.getMethodName(), - interceptorMethodConfig.getMethodDesc(), false)); - - if (!methodType.getReturnType().equals(Type.VOID_TYPE)) { - if (location.canChangeByReturn()) { - // 当回调函数有返回值时,需要更新到之前保存的栈上 - // TODO 这里应该有 type 的问题?需要检查是否要 box - Type returnType = methodType.getReturnType(); - Type stackSaverType = stackSaver.getType(bindingContext); - if (!returnType.equals(stackSaverType)) { - AsmOpUtils.unbox(toInsert, stackSaverType); - } - stackSaver.store(toInsert, bindingContext); - } else { - // 没有使用到回调函数的返回值的话,则需要从栈上清理掉 - int size = methodType.getReturnType().getSize(); - if (size == 1) { - AsmOpUtils.pop(toInsert); - } else if (size == 2) { - AsmOpUtils.pop2(toInsert); - } - } - } - - - TryCatchBlock errorHandlerTryCatchBlock = null; - // 生成的代码用try/catch包围起来 - if( exceptionHandlerConfig != null) { - LabelNode gotoDest = new LabelNode(); - - errorHandlerTryCatchBlock = new TryCatchBlock(methodProcessor.getMethodNode(), exceptionHandlerConfig.getSuppress()); - toInsert.insertBefore(toInsert.getFirst(), errorHandlerTryCatchBlock.getStartLabelNode()); - toInsert.add(new JumpInsnNode(Opcodes.GOTO, gotoDest)); - toInsert.add(errorHandlerTryCatchBlock.getEndLabelNode()); -// 这里怎么把栈上的数据保存起来?还是强制回调函数的第一个参数是 exception,后面的binding可以随便搞。 - -// MethodInsnNode printStackTrace = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V", false); -// toInsert.add(printStackTrace); - - errorHandler(methodProcessor, toInsert); - - toInsert.add(gotoDest); - } - -// System.err.println(Decompiler.toString(toInsert)); - - - stackSaveInsnList.add(toInsert); - stackSaveInsnList.add(stackLoadInsnList); - if (location.isWhenComplete()) { - methodProcessor.getMethodNode().instructions.insert(location.getInsnNode(), stackSaveInsnList); - }else { - methodProcessor.getMethodNode().instructions.insertBefore(location.getInsnNode(), stackSaveInsnList); - } - - if( exceptionHandlerConfig != null) { - errorHandlerTryCatchBlock.sort(); - } - - // inline callback - if(interceptorMethodConfig.isInline()) { -// Class forName = Class.forName(Type.getObjectType(interceptorMethodConfig.getOwner()).getClassName()); - - Class forName = classLoader.loadClass(Type.getObjectType(interceptorMethodConfig.getOwner()).getClassName()); - MethodNode toInlineMethodNode = AsmUtils.findMethod(AsmUtils.loadClass(forName).methods, interceptorMethodConfig.getMethodName(), interceptorMethodConfig.getMethodDesc()); - - methodProcessor.inline(interceptorMethodConfig.getOwner(), toInlineMethodNode); - } - if(exceptionHandlerConfig != null && exceptionHandlerConfig.isInline()) { -// Class forName = Class.forName(Type.getObjectType(exceptionHandlerConfig.getOwner()).getClassName()); - - Class forName = classLoader.loadClass(Type.getObjectType(exceptionHandlerConfig.getOwner()).getClassName()); - MethodNode toInlineMethodNode = AsmUtils.findMethod(AsmUtils.loadClass(forName).methods, exceptionHandlerConfig.getMethodName(), exceptionHandlerConfig.getMethodDesc()); - - methodProcessor.inline(exceptionHandlerConfig.getOwner(), toInlineMethodNode); - } - -// System.err.println(Decompiler.toString(methodProcessor.getMethodNode())); -// System.err.println(AsmUtils.toASMCode(methodProcessor.getMethodNode())); - } - - return locations; - } - - private void errorHandler(MethodProcessor methodProcessor, InsnList insnList) { -// MethodInsnNode printStackTrace = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "printStackTrace", "()V", false); -// insnList.add(printStackTrace); - // 第一个参数要求是 throwable ,或者一个exception ? - // 有很多 binding 并不能使用的,因为location不生效 - BindingContext bindingContext = new BindingContext(null, methodProcessor, null); - Type methodType = Type.getMethodType(this.exceptionHandlerConfig.getMethodDesc()); - Type[] argumentTypes = methodType.getArgumentTypes(); - List bindings = this.exceptionHandlerConfig.getBindings(); - if(bindings.size() + 1 != argumentTypes.length) { - throw new IllegalArgumentException("errorHandler bindings size do not match error method args size."); - } - if(!argumentTypes[0].equals(Type.getType(Throwable.class))) { - throw new IllegalArgumentException("errorHandler method first arg type must be Throwable."); - } - // 组装好要调用的 static 函数的参数 - for(Binding binding: bindings) { - if(binding.fromStack()) { - throw new IllegalArgumentException("errorHandler binding can not load value from stack!"); - } - binding.pushOntoStack(insnList, bindingContext); - // 检查 回调函数的参数类型,看是否要box一下 ,检查是否原始类型就可以了。 - if(AsmOpUtils.needBox(binding.getType(bindingContext))) { - AsmOpUtils.box(insnList, binding.getType(bindingContext)); - } - } - - insnList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, exceptionHandlerConfig.getOwner(), exceptionHandlerConfig.getMethodName(), - exceptionHandlerConfig.getMethodDesc(), false)); - - int size = methodType.getReturnType().getSize(); - if (size == 1) { - AsmOpUtils.pop(insnList); - } else if (size == 2) { - AsmOpUtils.pop2(insnList); - } - } - - public LocationMatcher getLocationMatcher() { - return locationMatcher; - } - - public void setLocationMatcher(LocationMatcher locationMatcher) { - this.locationMatcher = locationMatcher; - } - - public InterceptorMethodConfig getInterceptorMethodConfig() { - return interceptorMethodConfig; - } - - public void setInterceptorMethodConfig(InterceptorMethodConfig interceptorMethodConfig) { - this.interceptorMethodConfig = interceptorMethodConfig; - } - - public InterceptorMethodConfig getExceptionHandlerConfig() { - return exceptionHandlerConfig; - } - - public void setExceptionHandlerConfig(InterceptorMethodConfig exceptionHandlerConfig) { - this.exceptionHandlerConfig = exceptionHandlerConfig; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtEnter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtEnter.java deleted file mode 100644 index 4374faee2..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtEnter.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter.EnterInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.EnterLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = EnterInterceptorProcessorParser.class) -public @interface AtEnter { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - class EnterInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - LocationMatcher locationMatcher = new EnterLocationMatcher(); - - AtEnter atEnter = (AtEnter) annotationOnMethod; - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atEnter.inline(), - atEnter.suppress(), - atEnter.suppressHandler()); - - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtExceptionExit.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtExceptionExit.java deleted file mode 100644 index aaa746277..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtExceptionExit.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit.ExceptionExitInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.ExceptionExitLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = ExceptionExitInterceptorProcessorParser.class) -public @interface AtExceptionExit { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - Class onException() default Throwable.class; - - class ExceptionExitInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtExceptionExit atExceptionExit = (AtExceptionExit) annotationOnMethod; - - LocationMatcher locationMatcher = new ExceptionExitLocationMatcher(Type.getInternalName(atExceptionExit.onException()));; - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atExceptionExit.inline(), - atExceptionExit.suppress(), - atExceptionExit.suppressHandler()); - - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtExit.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtExit.java deleted file mode 100644 index 94280ff0d..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtExit.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit.ExitInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.ExitLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = ExitInterceptorProcessorParser.class) -public @interface AtExit { - boolean inline() default true; - Class suppress() default None.class; - Class suppressHandler() default Void.class; - - class ExitInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtExit atExit = (AtExit) annotationOnMethod; - - LocationMatcher locationMatcher = new ExitLocationMatcher(); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atExit.inline(), - atExit.suppress(), - atExit.suppressHandler()); - - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtFieldAccess.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtFieldAccess.java deleted file mode 100644 index aace229b1..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtFieldAccess.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtFieldAccess.FieldAccessInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.FieldAccessLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = FieldAccessInterceptorProcessorParser.class) -public @interface AtFieldAccess { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - java.lang.Class owner() default Void.class; - - java.lang.Class type() default Void.class; - - String name(); - - int count() default -1; - - int flags() default Location.ACCESS_READ | Location.ACCESS_WRITE; - - boolean whenComplete() default false; - - class FieldAccessInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtFieldAccess atFieldAccess = (AtFieldAccess) annotationOnMethod; - - String ownerClass = null; - String fieldDesc = null; - if(! atFieldAccess.owner().equals(Void.class)) { - ownerClass = Type.getType(atFieldAccess.owner()).getInternalName(); - } - if(!atFieldAccess.type().equals(Void.class)) { - fieldDesc = Type.getType(atFieldAccess.type()).getDescriptor(); - } - - LocationMatcher locationMatcher = new FieldAccessLocationMatcher( - ownerClass, - fieldDesc, atFieldAccess.name(), atFieldAccess.count(), - atFieldAccess.flags(), atFieldAccess.whenComplete()); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atFieldAccess.inline(), - atFieldAccess.suppress(), - atFieldAccess.suppressHandler()); - - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtInvoke.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtInvoke.java deleted file mode 100644 index ff76e8e0c..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtInvoke.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvoke.InvokeInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.InvokeLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = InvokeInterceptorProcessorParser.class) -public @interface AtInvoke { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - Class owner() default Void.class; - - String name(); - - String desc() default ""; - - int count() default -1; - - boolean whenComplete() default false; - - /** - * method name excludes - * @return - */ - String[] excludes() default {}; - - class InvokeInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtInvoke atInvoke = (AtInvoke) annotationOnMethod; - - String owner = null; - String desc = null; - if (!atInvoke.owner().equals(Void.class)) { - owner = Type.getType(atInvoke.owner()).getInternalName(); - } - if (atInvoke.desc().isEmpty()) { - desc = null; - } - - List excludes = new ArrayList(); - for (String exclude : atInvoke.excludes()) { - excludes.add(exclude); - } - - LocationMatcher locationMatcher = new InvokeLocationMatcher(owner, atInvoke.name(), desc, atInvoke.count(), - atInvoke.whenComplete(), excludes); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atInvoke.inline(), - atInvoke.suppress(), - atInvoke.suppressHandler()); - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtInvokeException.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtInvokeException.java deleted file mode 100644 index a12de47f9..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtInvokeException.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvokeException.InvokeExceptionInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.InvokeLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -/** - * - * @author hengyunabc 2020-05-03 - * - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = InvokeExceptionInterceptorProcessorParser.class) -public @interface AtInvokeException { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - Class owner() default Void.class; - - /** - * method name - * - * @return - */ - String name(); - - String desc() default ""; - - int count() default -1; - - String[] excludes() default {}; - - class InvokeExceptionInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtInvokeException atInvokeException = (AtInvokeException) annotationOnMethod; - - String owner = null; - String desc = null; - if (!atInvokeException.owner().equals(Void.class)) { - owner = Type.getType(atInvokeException.owner()).getInternalName(); - } - if (atInvokeException.desc().isEmpty()) { - desc = null; - } - - List excludes = new ArrayList(); - for (String exclude : atInvokeException.excludes()) { - excludes.add(exclude); - } - - LocationMatcher locationMatcher = new InvokeLocationMatcher(owner, atInvokeException.name(), desc, - atInvokeException.count(), true, excludes, true); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atInvokeException.inline(), - atInvokeException.suppress(), - atInvokeException.suppressHandler()); - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtLine.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtLine.java deleted file mode 100644 index 3a6f6e6ad..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtLine.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtLine.LineInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.LineLocationMatcher; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = LineInterceptorProcessorParser.class) -public @interface AtLine { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - int[] lines(); - - class LineInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtLine atLine = (AtLine) annotationOnMethod; - - LocationMatcher locationMatcher = new LineLocationMatcher(atLine.lines()); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atLine.inline(), - atLine.suppress(), - atLine.suppressHandler()); - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtSyncEnter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtSyncEnter.java deleted file mode 100644 index 07581a4dc..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtSyncEnter.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtSyncEnter.SyncEnterInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; -import com.taobao.arthas.bytekit.asm.location.SyncLocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = SyncEnterInterceptorProcessorParser.class) -public @interface AtSyncEnter { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - int count() default -1; - boolean whenComplete() default false; - - class SyncEnterInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtSyncEnter atSyncEnter = (AtSyncEnter) annotationOnMethod; - - LocationMatcher locationMatcher = new SyncLocationMatcher(Opcodes.MONITORENTER, atSyncEnter.count(), atSyncEnter.whenComplete()); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atSyncEnter.inline(), - atSyncEnter.suppress(), - atSyncEnter.suppressHandler()); - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtSyncExit.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtSyncExit.java deleted file mode 100644 index 2411eceb6..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtSyncExit.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtSyncExit.SyncExitInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; -import com.taobao.arthas.bytekit.asm.location.SyncLocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = SyncExitInterceptorProcessorParser.class) -public @interface AtSyncExit { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - int count() default -1; - boolean whenComplete() default false; - - class SyncExitInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtSyncExit atSyncExit = (AtSyncExit) annotationOnMethod; - - LocationMatcher locationMatcher = new SyncLocationMatcher(Opcodes.MONITOREXIT, atSyncExit.count(), atSyncExit.whenComplete()); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atSyncExit.inline(), - atSyncExit.suppress(), - atSyncExit.suppressHandler()); - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtThrow.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtThrow.java deleted file mode 100644 index 859525554..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/AtThrow.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Method; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtThrow.ThrowInterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; -import com.taobao.arthas.bytekit.asm.location.ThrowLocationMatcher; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -@InterceptorParserHander(parserHander = ThrowInterceptorProcessorParser.class) -public @interface AtThrow { - boolean inline() default true; - - Class suppress() default None.class; - - Class suppressHandler() default Void.class; - - int count() default -1; - - class ThrowInterceptorProcessorParser implements InterceptorProcessorParser { - - @Override - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod) { - - AtThrow atThrow = (AtThrow) annotationOnMethod; - - LocationMatcher locationMatcher = new ThrowLocationMatcher(atThrow.count()); - - return InterceptorParserUtils.createInterceptorProcessor(method, - locationMatcher, - atThrow.inline(), - atThrow.suppress(), - atThrow.suppressHandler()); - } - - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/BindingParserUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/BindingParserUtils.java deleted file mode 100644 index 5228c3014..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/BindingParserUtils.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.binding.annotation.BindingParser; -import com.taobao.arthas.bytekit.asm.binding.annotation.BindingParserHandler; -import com.taobao.arthas.bytekit.utils.InstanceUtils; - -public class BindingParserUtils { - - public static List parseBindings(Method method) { - // 从 parameter 里解析出来 binding - List bindings = new ArrayList(); - Annotation[][] parameterAnnotations = method.getParameterAnnotations(); - for (int parameterIndex = 0; parameterIndex < parameterAnnotations.length; ++parameterIndex) { - Annotation[] annotationsOnParameter = parameterAnnotations[parameterIndex]; - for (int j = 0; j < annotationsOnParameter.length; ++j) { - - Annotation[] annotationsOnBinding = annotationsOnParameter[j].annotationType().getAnnotations(); - for (Annotation annotationOnBinding : annotationsOnBinding) { - if (BindingParserHandler.class.isAssignableFrom(annotationOnBinding.annotationType())) { - BindingParserHandler bindingParserHandler = (BindingParserHandler) annotationOnBinding; - BindingParser bindingParser = InstanceUtils.newInstance(bindingParserHandler.parser()); - Binding binding = bindingParser.parse(annotationsOnParameter[j]); - bindings.add(binding); - } - } - } - } - return bindings; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/EmptySuppressHandler.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/EmptySuppressHandler.java deleted file mode 100644 index 4568199d9..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/EmptySuppressHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -public class EmptySuppressHandler { - - @ExceptionHandler - public static void onSuppress() { - - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/ExceptionHandler.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/ExceptionHandler.java deleted file mode 100644 index 384906832..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/ExceptionHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.METHOD) -public @interface ExceptionHandler { - boolean inline() default true; -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/ExceptionHandlerUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/ExceptionHandlerUtils.java deleted file mode 100644 index 65bfce33b..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/ExceptionHandlerUtils.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.binding.ThrowableBinding; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorMethodConfig; -import com.taobao.arthas.bytekit.utils.AnnotationUtils; -import com.taobao.arthas.bytekit.utils.ReflectionUtils; -import com.taobao.arthas.bytekit.utils.ReflectionUtils.MethodCallback; -import com.taobao.arthas.bytekit.utils.ReflectionUtils.MethodFilter; - -public class ExceptionHandlerUtils { - - public static InterceptorMethodConfig errorHandlerMethodConfig(Class suppress, Class handlerClass) { - - // TODO 要解析 errorHander Class里的内容 - final InterceptorMethodConfig errorHandlerMethodConfig = new InterceptorMethodConfig(); - - if(suppress.equals(None.class)) { - suppress = Throwable.class; - } - errorHandlerMethodConfig.setSuppress(Type.getType(suppress).getInternalName()); - - if (!handlerClass.equals(Void.class)) { - // find method with @ExceptionHandler - ReflectionUtils.doWithMethods(handlerClass, new MethodCallback() { - - @Override - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { - for (Annotation onMethodAnnotation : method.getAnnotations()) { - if (ExceptionHandler.class.isAssignableFrom(onMethodAnnotation.annotationType())) { - - if (!Modifier.isStatic(method.getModifiers())) { - throw new IllegalArgumentException("method must be static. method: " + method); - } - - ExceptionHandler handler = (ExceptionHandler) onMethodAnnotation; - - errorHandlerMethodConfig.setInline(handler.inline()); - - List errorHandlerBindings = BindingParserUtils.parseBindings(method); - // 检查第一个 bidning要是 Throwable Binding - if (errorHandlerBindings.size() == 0) { - throw new IllegalArgumentException( - "error handler bingins must have at least a binding"); - } - if (!(errorHandlerBindings.get(0) instanceof ThrowableBinding)) { - throw new IllegalArgumentException( - "error handler bingins first binding must be ThrowableBinding."); - } - // 去掉第一个 ThrowableBinding - // TODO 可能要copy一下,保证可以修改成功 - errorHandlerBindings.remove(0); - errorHandlerMethodConfig.setBindings(errorHandlerBindings); - errorHandlerMethodConfig.setOwner(Type.getInternalName(method.getDeclaringClass())); - errorHandlerMethodConfig.setMethodName(method.getName()); - errorHandlerMethodConfig.setMethodDesc(Type.getMethodDescriptor(method)); - } - } - - } - - }, new MethodFilter() { - - @Override - public boolean matches(Method method) { - return AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null; - } - - }); - } - - if (errorHandlerMethodConfig.getMethodDesc() == null) { - return null; - } - - return errorHandlerMethodConfig; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/InterceptorParserHander.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/InterceptorParserHander.java deleted file mode 100644 index 82603f0d5..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/InterceptorParserHander.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -import com.taobao.arthas.bytekit.asm.interceptor.parser.InterceptorProcessorParser; - -@Documented -@Retention(RetentionPolicy.RUNTIME) -@java.lang.annotation.Target(ElementType.ANNOTATION_TYPE) -public @interface InterceptorParserHander { - - Class parserHander(); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/InterceptorParserUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/InterceptorParserUtils.java deleted file mode 100644 index 49fab8494..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/InterceptorParserUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorMethodConfig; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.location.LocationMatcher; - -import java.lang.reflect.Method; -import java.util.List; - -public class InterceptorParserUtils { - - public static InterceptorProcessor createInterceptorProcessor( - Method method, - LocationMatcher locationMatcher, - boolean inline, - Class suppress, - Class suppressHandler) { - - InterceptorProcessor interceptorProcessor = new InterceptorProcessor(method.getDeclaringClass().getClassLoader()); - - //locationMatcher - interceptorProcessor.setLocationMatcher(locationMatcher); - - //interceptorMethodConfig - InterceptorMethodConfig interceptorMethodConfig = new InterceptorMethodConfig(); - interceptorProcessor.setInterceptorMethodConfig(interceptorMethodConfig); - interceptorMethodConfig.setOwner(Type.getInternalName(method.getDeclaringClass())); - interceptorMethodConfig.setMethodName(method.getName()); - interceptorMethodConfig.setMethodDesc(Type.getMethodDescriptor(method)); - - //inline - interceptorMethodConfig.setInline(inline); - - //bindings - List bindings = BindingParserUtils.parseBindings(method); - interceptorMethodConfig.setBindings(bindings); - - //errorHandlerMethodConfig - InterceptorMethodConfig errorHandlerMethodConfig = ExceptionHandlerUtils - .errorHandlerMethodConfig(suppress, suppressHandler); - if (errorHandlerMethodConfig != null) { - interceptorProcessor.setExceptionHandlerConfig(errorHandlerMethodConfig); - } - - return interceptorProcessor; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/None.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/None.java deleted file mode 100644 index f4c87c178..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/None.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -/** - * 用于声明没有异常 - * @author hengyunabc - * - */ -public class None extends Throwable { - private static final long serialVersionUID = 1L; - - private None() { - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/PrintSuppressHandler.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/PrintSuppressHandler.java deleted file mode 100644 index 191cdb0d3..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/annotation/PrintSuppressHandler.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.annotation; - -import com.taobao.arthas.bytekit.asm.binding.Binding; - -public class PrintSuppressHandler { - - @ExceptionHandler(inline = true) - public static void onSuppress(@Binding.Throwable Throwable e) { - e.printStackTrace(); - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/DefaultInterceptorClassParser.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/DefaultInterceptorClassParser.java deleted file mode 100644 index f1c703449..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/DefaultInterceptorClassParser.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.parser; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.InterceptorParserHander; -import com.taobao.arthas.bytekit.utils.InstanceUtils; -import com.taobao.arthas.bytekit.utils.ReflectionUtils; -import com.taobao.arthas.bytekit.utils.ReflectionUtils.MethodCallback; - -public class DefaultInterceptorClassParser implements InterceptorClassParser { - - @Override - public List parse(Class clazz) { - final List result = new ArrayList(); - - MethodCallback methodCallback = new MethodCallback() { - - @Override - public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { - for (Annotation onMethodAnnotation : method.getAnnotations()) { - for (Annotation onAnnotation : onMethodAnnotation.annotationType().getAnnotations()) { - if (InterceptorParserHander.class.isAssignableFrom(onAnnotation.annotationType())) { - - if (!Modifier.isStatic(method.getModifiers())) { - throw new IllegalArgumentException("method must be static. method: " + method); - } - - InterceptorParserHander handler = (InterceptorParserHander) onAnnotation; - InterceptorProcessorParser interceptorProcessorParser = InstanceUtils - .newInstance(handler.parserHander()); - InterceptorProcessor interceptorProcessor = interceptorProcessorParser.parse(method, - onMethodAnnotation); - result.add(interceptorProcessor); - } - } - } - } - - }; - ReflectionUtils.doWithMethods(clazz, methodCallback); - - return result; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/InterceptorClassParser.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/InterceptorClassParser.java deleted file mode 100644 index e28c66eb0..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/InterceptorClassParser.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.parser; - -import java.util.List; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; - -public interface InterceptorClassParser { - - public List parse(Class clazz); -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/InterceptorProcessorParser.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/InterceptorProcessorParser.java deleted file mode 100644 index 233ff4d24..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/interceptor/parser/InterceptorProcessorParser.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor.parser; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; - -public interface InterceptorProcessorParser { - - public InterceptorProcessor parse(Method method, Annotation annotationOnMethod); -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/AccessLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/AccessLocationMatcher.java deleted file mode 100644 index e773b781a..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/AccessLocationMatcher.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -public abstract class AccessLocationMatcher implements LocationMatcher { - protected int count; - - /** - * flags identifying which type of access should be used to identify the - * trigger. this is either ACCESS_READ, ACCESS_WRITE or an OR of these two - * values - */ - protected int flags; - - /** - * flag which is false if the trigger should be inserted before the field - * access is performed and true if it should be inserted after - */ - protected boolean whenComplete; - - AccessLocationMatcher(int count, int flags, boolean whenComplete) { - this.count = count; - this.flags = flags; - this.whenComplete = whenComplete; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/EnterLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/EnterLocationMatcher.java deleted file mode 100644 index ccb93b672..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/EnterLocationMatcher.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.EnterLocation; -import com.taobao.arthas.bytekit.asm.location.filter.LocationFilter; - -public class EnterLocationMatcher implements LocationMatcher { - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode enterInsnNode = methodProcessor.getEnterInsnNode(); - - LocationFilter locationFilter = methodProcessor.getLocationFilter(); - if (locationFilter.allow(enterInsnNode, LocationType.ENTER, true)) { - EnterLocation enterLocation = new EnterLocation(enterInsnNode); - locations.add(enterLocation); - } - return locations; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ExceptionExitLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ExceptionExitLocationMatcher.java deleted file mode 100644 index 88fa9343c..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ExceptionExitLocationMatcher.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.TryCatchBlock; -import com.taobao.arthas.bytekit.asm.location.Location.ExceptionExitLocation; -import com.taobao.arthas.bytekit.asm.location.filter.LocationFilter; - -public class ExceptionExitLocationMatcher implements LocationMatcher { - - private String exception; - - public ExceptionExitLocationMatcher() { - this(Type.getType(Throwable.class).getInternalName()); - } - - public ExceptionExitLocationMatcher(String exception) { - this.exception = exception; - } - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - TryCatchBlock tryCatchBlock = methodProcessor.initTryCatchBlock(exception); - - LabelNode endLabelNode = tryCatchBlock.getEndLabelNode(); - - LocationFilter locationFilter = methodProcessor.getLocationFilter(); - if (locationFilter.allow(endLabelNode, LocationType.EXCEPTION_EXIT, false)) { - locations.add(new ExceptionExitLocation(tryCatchBlock.getEndLabelNode())); - } - return locations; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ExitLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ExitLocationMatcher.java deleted file mode 100644 index c532ad123..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ExitLocationMatcher.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.ExitLocation; -import com.taobao.arthas.bytekit.asm.location.filter.LocationFilter; - -public class ExitLocationMatcher implements LocationMatcher { - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - while (insnNode != null) { - if (insnNode instanceof InsnNode) { - InsnNode node = (InsnNode) insnNode; - if (matchExit(node)) { - LocationFilter locationFilter = methodProcessor.getLocationFilter(); - if (locationFilter.allow(node, LocationType.EXIT, false)) { - ExitLocation ExitLocation = new ExitLocation(node); - locations.add(ExitLocation); - } - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } - - public boolean matchExit(InsnNode node) { - switch (node.getOpcode()) { - case Opcodes.RETURN: // empty stack - case Opcodes.IRETURN: // 1 before n/a after - case Opcodes.FRETURN: // 1 before n/a after - case Opcodes.ARETURN: // 1 before n/a after - case Opcodes.LRETURN: // 2 before n/a after - case Opcodes.DRETURN: // 2 before n/a after - return true; - } - return false; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/FieldAccessLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/FieldAccessLocationMatcher.java deleted file mode 100644 index fa537e8f3..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/FieldAccessLocationMatcher.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FieldInsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.FieldAccessLocation; - -public class FieldAccessLocationMatcher extends AccessLocationMatcher { - - /** - * maybe null - */ - private String ownerClass; - - /** - * the name of the field being accessed at the point where the trigger point - * should be inserted - */ - private String fieldName; - - /** - * The field's descriptor (see {@link org.objectweb.asm.Type}). maybe null. - */ - private String fieldDesc; - - - public FieldAccessLocationMatcher(String ownerClass, String fieldDesc, String fieldName, int count, int flags, - boolean whenComplete) { - super(count, flags, whenComplete); - this.ownerClass = ownerClass; - this.fieldDesc = fieldDesc; - this.fieldName = fieldName; - } - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - int matchedCount = 0; - while (insnNode != null) { - if (insnNode instanceof FieldInsnNode) { - FieldInsnNode fieldInsnNode = (FieldInsnNode) insnNode; - - if (matchField(fieldInsnNode)) { - matchedCount++; - if (count <= 0 || count == matchedCount) { - FieldAccessLocation fieldAccessLocation = new FieldAccessLocation(fieldInsnNode, count, flags, whenComplete); - locations.add(fieldAccessLocation); - } - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } - - private boolean matchField(FieldInsnNode fieldInsnNode) { - if (!fieldName.equals(fieldInsnNode.name)) { - return false; - } - - if (this.fieldDesc != null && !this.fieldDesc.equals(fieldInsnNode.desc)) { - return false; - } - - switch (fieldInsnNode.getOpcode()) { - case Opcodes.GETSTATIC: - case Opcodes.GETFIELD: { - if ((flags & Location.ACCESS_READ) == 0) { - return false; - } - } - break; - case Opcodes.PUTSTATIC: - case Opcodes.PUTFIELD: { - if ((flags & Location.ACCESS_WRITE) == 0) { - return false; - } - } - break; - } - if (ownerClass != null) { - if (!ownerClass.equals(fieldInsnNode.owner)) { - return false; - } - } - return true; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/InvokeLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/InvokeLocationMatcher.java deleted file mode 100644 index 844658b29..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/InvokeLocationMatcher.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.JumpInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.TryCatchBlock; -import com.taobao.arthas.bytekit.asm.location.Location.InvokeExceptionExitLocation; -import com.taobao.arthas.bytekit.asm.location.Location.InvokeLocation; -import com.taobao.arthas.bytekit.asm.location.filter.LocationFilter; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.MatchUtils; - -/** - * - * @author hengyunabc - * - */ -public class InvokeLocationMatcher implements LocationMatcher { - - /** - * the name of the method being invoked at the point where the trigger point - * should be inserted. maybe null, when null, match all method invoke. - */ - private String methodName; - - /** - * the name of the type to which the method belongs or null if any type will do - */ - private String owner; - - /** - * the method signature in externalised form, maybe null. - */ - private String desc; - - /** - * count identifying which invocation should be taken as the trigger point. if - * not specified as a parameter this defaults to the first invocation. - */ - private int count; - - /** - * flag which is false if the trigger should be inserted before the method - * invocation is performed and true if it should be inserted after - */ - private boolean whenComplete; - - /** - * wildcard matcher to exclude the invoke class, such as java.* to exclude jdk - * invoke. - */ - private List excludes = new ArrayList(); - - private boolean atInvokeExcpetionExit = false; - - public InvokeLocationMatcher(String owner, String methodName, String desc, int count, boolean whenComplete, - List excludes, boolean atInvokeExcpetionExit) { - super(); - this.owner = owner; - this.methodName = methodName; - this.desc = desc; - this.count = count; - this.whenComplete = whenComplete; - this.excludes = excludes; - this.atInvokeExcpetionExit = atInvokeExcpetionExit; - } - - public InvokeLocationMatcher(String owner, String methodName, String desc, int count, boolean whenComplete, - List excludes) { - this(owner, methodName, desc, count, whenComplete, excludes, false); - } - - public InvokeLocationMatcher(String owner, String methodName, String desc, int count, boolean whenComplete) { - this(owner, methodName, desc, count, whenComplete, new ArrayList()); - } - - @Override - public List match(MethodProcessor methodProcessor) { - if (this.atInvokeExcpetionExit) { - return matchForException(methodProcessor); - } - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - LocationFilter locationFilter = methodProcessor.getLocationFilter(); - - LocationType locationType = whenComplete ? LocationType.INVOKE_COMPLETED : LocationType.INVOKE; - - int matchedCount = 0; - while (insnNode != null) { - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - - if (matchCall(methodInsnNode)) { - if(locationFilter.allow(methodInsnNode, locationType, this.whenComplete)) { - matchedCount++; - if (count <= 0 || count == matchedCount) { - InvokeLocation invokeLocation = new InvokeLocation(methodInsnNode, count, whenComplete); - locations.add(invokeLocation); - } - } - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } - - public List matchForException(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - MethodNode methodNode = methodProcessor.getMethodNode(); - - List methodInsnNodes = new ArrayList(); - - LocationFilter locationFilter = methodProcessor.getLocationFilter(); - - LocationType locationType = LocationType.INVOKE_EXCEPTION_EXIT; - - int matchedCount = 0; - while (insnNode != null) { - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - - if (matchCall(methodInsnNode)) { - if(locationFilter.allow(methodInsnNode, locationType, this.whenComplete)) { - matchedCount++; - if (count <= 0 || count == matchedCount) { - methodInsnNodes.add(methodInsnNode); - } - } - } - } - insnNode = insnNode.getNext(); - } - - // insert try/catch - for (MethodInsnNode methodInsnNode : methodInsnNodes) { - TryCatchBlock tryCatchBlock = new TryCatchBlock(methodNode); - - InsnList toInsert = new InsnList(); - - LabelNode gotoDest = new LabelNode(); - - LabelNode startLabelNode = tryCatchBlock.getStartLabelNode(); - LabelNode endLabelNode = tryCatchBlock.getEndLabelNode(); - - toInsert.add(new JumpInsnNode(Opcodes.GOTO, gotoDest)); - toInsert.add(endLabelNode); - AsmOpUtils.throwException(toInsert); - locations.add(new InvokeExceptionExitLocation(methodInsnNode, endLabelNode)); - - toInsert.add(gotoDest); - - methodNode.instructions.insertBefore(methodInsnNode, startLabelNode); - methodNode.instructions.insert(methodInsnNode, toInsert); - - tryCatchBlock.sort(); - } - - return locations; - } - - private boolean matchCall(MethodInsnNode methodInsnNode) { - - if (methodName != null && !methodName.isEmpty()) { - if (!this.methodName.equals(methodInsnNode.name)) { - return false; - } - } - - if (!excludes.isEmpty()) { - String ownerClassName = Type.getObjectType(methodInsnNode.owner).getClassName(); - for (String exclude : excludes) { - if (MatchUtils.wildcardMatch(ownerClassName, exclude)) { - return false; - } - } - } - - if (this.owner != null && !this.owner.equals(methodInsnNode.owner)) { - return false; - } - - if (this.desc != null && !desc.equals(methodInsnNode.desc)) { - return false; - } - - return true; - - } - - public String getMethodName() { - return methodName; - } - - public void setMethodName(String methodName) { - this.methodName = methodName; - } - - public String getOwner() { - return owner; - } - - public void setOwner(String owner) { - this.owner = owner; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public int getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } - - public boolean isWhenComplete() { - return whenComplete; - } - - public void setWhenComplete(boolean whenComplete) { - this.whenComplete = whenComplete; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LineLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LineLocationMatcher.java deleted file mode 100644 index a4ee285e4..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LineLocationMatcher.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LineNumberNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.LineLocation; - -public class LineLocationMatcher implements LocationMatcher { - - private List targetLines = Collections.emptyList(); - - public LineLocationMatcher(int... targetLines) { - if (targetLines != null) { - ArrayList result = new ArrayList(targetLines.length); - for (int targetLine : targetLines) { - result.add(targetLine); - } - this.targetLines = result; - } - } - - public LineLocationMatcher(List targetLines) { - this.targetLines = targetLines; - } - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - while (insnNode != null) { - if (insnNode instanceof LineNumberNode) { - LineNumberNode lineNumberNode = (LineNumberNode) insnNode; - if (match(lineNumberNode.line)) { - locations.add(new LineLocation(lineNumberNode, lineNumberNode.line)); - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } - - private boolean match(int line) { - for (int targetLine : targetLines) { - if (targetLine == -1) { - return true; - } else if (line == targetLine) { - return true; - } - - } - return false; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/Location.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/Location.java deleted file mode 100644 index e024b577d..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/Location.java +++ /dev/null @@ -1,696 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FieldInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.binding.BindingContext; -import com.taobao.arthas.bytekit.asm.binding.StackSaver; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; - -/** - * Specifies a location in a method at which a rule trigger should be inserted - */ -public abstract class Location { - - AbstractInsnNode insnNode; - - boolean whenComplete = false; - - boolean stackNeedSave = false; - - public Location(AbstractInsnNode insnNode) { - this(insnNode, false); - } - - public Location(AbstractInsnNode insnNode, boolean whenComplete) { - this.insnNode = insnNode; - this.whenComplete = whenComplete; - } - - public boolean isWhenComplete() { - return whenComplete; - } - - public AbstractInsnNode getInsnNode() { - return insnNode; - } - - /** - * 标记在这个location,栈上原来的值可以被 callback 函数的return值替换掉 - * - * @return - */ - public boolean canChangeByReturn() { - return false; - } - - public boolean isStackNeedSave() { - return stackNeedSave; - } - - public StackSaver getStackSaver() { - throw new UnsupportedOperationException("this location do not StackSaver, type:" + getLocationType()); - } - - /** - * identify the type of this location - * - * @return the type of this location - */ - public abstract LocationType getLocationType(); - - /** - * flag indicating that a field access location refers to field READ operations - */ - public static final int ACCESS_READ = 1; - - /** - * flag indicating that a field access location refers to field WRITE operations - */ - public static final int ACCESS_WRITE = 2; - - /** - * location identifying a method enter trigger point - */ - static class EnterLocation extends Location { - public EnterLocation(AbstractInsnNode enterInsnNode) { - super(enterInsnNode); - this.insnNode = enterInsnNode; - } - - public LocationType getLocationType() { - return LocationType.ENTER; - } - - } - - /** - * location identifying a method line trigger point - */ - public static class LineLocation extends Location { - /** - * the line at which the trigger point should be inserted - */ - private int targetLine; - - public LineLocation(AbstractInsnNode insnNode, int targetLine) { - super(insnNode); - this.targetLine = targetLine; - } - - public LocationType getLocationType() { - return LocationType.LINE; - } - - } - - /** - * location identifying a generic access trigger point - */ - private static abstract class AccessLocation extends Location { - /** - * count identifying which access should be taken as the trigger point. if not - * specified as a parameter this defaults to the first access. - */ - protected int count; - - /** - * flags identifying which type of access should be used to identify the - * trigger. this is either ACCESS_READ, ACCESS_WRITE or an OR of these two - * values - */ - protected int flags; - - protected AccessLocation(AbstractInsnNode insnNode, int count, int flags, boolean whenComplete) { - super(insnNode, whenComplete); - this.count = count; - this.flags = flags; - } - - public LocationType getLocationType() { - if ((flags & ACCESS_WRITE) != 0) { - if (whenComplete) { - return LocationType.WRITE_COMPLETED; - } else { - return LocationType.WRITE; - } - } else { - if (whenComplete) { - return LocationType.READ_COMPLETED; - } else { - return LocationType.READ; - } - } - } - } - - /** - * location identifying a field access trigger point - */ - public static class FieldAccessLocation extends AccessLocation { - - public FieldAccessLocation(FieldInsnNode fieldInsnNode, int count, int flags, boolean whenComplete) { - super(fieldInsnNode, count, flags, whenComplete); - } - - } - - /** - * location identifying a variable access trigger point - */ - private static class VariableAccessLocation extends AccessLocation { - /** - * the name of the variable being accessed at the point where the trigger point - * should be inserted - */ - private String variableName; - - /** - * flag which is true if the name is a method parameter index such as $0, $1 etc - * otherwise false - */ - private boolean isIndex; - - protected VariableAccessLocation(AbstractInsnNode insnNode, String variablename, int count, int flags, - boolean whenComplete) { - super(insnNode, count, flags, whenComplete); - this.variableName = variablename; - isIndex = variablename.matches("[0-9]+"); - } - - public LocationType getLocationType() { - if ((flags & ACCESS_WRITE) != 0) { - if (whenComplete) { - return LocationType.WRITE_COMPLETED; - } else { - return LocationType.WRITE; - } - } else { - if (whenComplete) { - return LocationType.READ_COMPLETED; - } else { - return LocationType.READ; - } - } - } - - } - - /** - * location identifying a method invocation trigger point - */ - public static class InvokeLocation extends Location implements MethodInsnNodeWare { - - /** - * count identifying which invocation should be taken as the trigger point. if - * not specified as a parameter this defaults to the first invocation. - */ - private int count; - - public InvokeLocation(MethodInsnNode insnNode, int count, boolean whenComplete) { - super(insnNode, whenComplete); - this.count = count; - this.stackNeedSave = false; - } - - @Override - public boolean canChangeByReturn() { - // 对于 invoke ,只有在 complete 时,才能有返回值 - return whenComplete; - } - - public int getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } - - public LocationType getLocationType() { - if (whenComplete) { - return LocationType.INVOKE_COMPLETED; - } else { - return LocationType.INVOKE; - } - } - - @Override - public StackSaver getStackSaver() { - StackSaver stackSaver = null; - if(whenComplete) { - stackSaver = new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - AbstractInsnNode insnNode = bindingContext.getLocation().getInsnNode(); - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - String uniqueNameForMethod = AsmUtils.uniqueNameForMethod(methodInsnNode.owner, methodInsnNode.name, - methodInsnNode.desc); - Type invokeReturnType = Type.getMethodType(methodInsnNode.desc).getReturnType(); - - if(!invokeReturnType.equals(Type.VOID_TYPE)) { - LocalVariableNode invokeReturnVariableNode = methodProcessor.initInvokeReturnVariableNode( - uniqueNameForMethod, invokeReturnType); - AsmOpUtils.storeVar(instructions, invokeReturnType, invokeReturnVariableNode.index); - } - } else { - throw new IllegalArgumentException( - "InvokeReturnBinding location is not MethodInsnNode, insnNode: " + insnNode); - } - - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - AbstractInsnNode insnNode = bindingContext.getLocation().getInsnNode(); - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - String uniqueNameForMethod = AsmUtils.uniqueNameForMethod(methodInsnNode.owner, methodInsnNode.name, - methodInsnNode.desc); - Type invokeReturnType = Type.getMethodType(methodInsnNode.desc).getReturnType(); - - if(!invokeReturnType.equals(Type.VOID_TYPE)) { - LocalVariableNode invokeReturnVariableNode = methodProcessor.initInvokeReturnVariableNode( - uniqueNameForMethod, invokeReturnType); - AsmOpUtils.loadVar(instructions, invokeReturnType, invokeReturnVariableNode.index); - } - } else { - throw new IllegalArgumentException( - "InvokeReturnBinding location is not MethodInsnNode, insnNode: " + insnNode); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - return Type.getMethodType(methodInsnNode.desc).getReturnType(); - } - - }; - }else { - stackSaver = new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - // 需要从要调用的 函数的 des ,找到参数的类型,再从栈上一个个吐出来,再保存到数组里 - Location location = bindingContext.getLocation(); - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - if(location instanceof InvokeLocation) { - InvokeLocation invokeLocation = (InvokeLocation) location; - // 如果是非 static的,会有this指针 - MethodInsnNode methodInsnNode = (MethodInsnNode)invokeLocation.getInsnNode(); - Type methodType = Type.getMethodType(methodInsnNode.desc); - boolean isStatic = AsmUtils.isStatic(methodInsnNode); - Type[] argumentTypes = methodType.getArgumentTypes(); - -// // 如果是非static,则存放到数组的index要多 1 -// AsmOpUtils.push(instructions, argumentTypes.length + (isStatic ? 0 : 1)); -// AsmOpUtils.newArray(instructions, AsmOpUtils.OBJECT_TYPE); -// LocalVariableNode invokeArgsVariableNode = methodProcessor.initInvokeArgsVariableNode(); -// AsmOpUtils.storeVar(instructions, AsmOpUtils.OBJECT_ARRAY_TYPE, invokeArgsVariableNode.index); - - // 从invoke的参数的后面,一个个存到数组里 -// for(int i = argumentTypes.length - 1; i >= 0 ; --i) { -// AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_ARRAY_TYPE, invokeArgsVariableNode.index); -// -// AsmOpUtils.swap(instructions, argumentTypes[i], AsmOpUtils.OBJECT_ARRAY_TYPE); -// // 如果是非static,则存放到数组的index要多 1 -// AsmOpUtils.push(instructions, i + (isStatic ? 0 : 1)); -// AsmOpUtils.swap(instructions, argumentTypes[i], Type.INT_TYPE); -// -// AsmOpUtils.box(instructions, argumentTypes[i]); -// AsmOpUtils.arrayStore(instructions, AsmOpUtils.OBJECT_TYPE); -// -// } - // 处理this -// if(!isStatic) { -// AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_ARRAY_TYPE, invokeArgsVariableNode.index); -// -// AsmOpUtils.swap(instructions, AsmOpUtils.OBJECT_TYPE, AsmOpUtils.OBJECT_ARRAY_TYPE); -// AsmOpUtils.push(instructions, 0); -// AsmOpUtils.swap(instructions, AsmOpUtils.OBJECT_TYPE, Type.INT_TYPE); -// AsmOpUtils.arrayStore(instructions, AsmOpUtils.OBJECT_TYPE); -// } - - }else { - throw new IllegalArgumentException("location is not a InvokeLocation, location: " + location); - } - - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - // 从数组里取出来,一个个再放到栈上,要检查是否要unbox - Location location = bindingContext.getLocation(); - MethodProcessor methodProcessor = bindingContext.getMethodProcessor(); - LocalVariableNode invokeArgsVariableNode = methodProcessor.initInvokeArgsVariableNode(); - - if(location instanceof InvokeLocation) { - InvokeLocation invokeLocation = (InvokeLocation) location; - // 如果是非 static的,会有this指针 - MethodInsnNode methodInsnNode = (MethodInsnNode)invokeLocation.getInsnNode(); - Type methodType = Type.getMethodType(methodInsnNode.desc); - boolean isStatic = AsmUtils.isStatic(methodInsnNode); - Type[] argumentTypes = methodType.getArgumentTypes(); - -// if(!isStatic) { -// // 取出this -// AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_ARRAY_TYPE, invokeArgsVariableNode.index); -// AsmOpUtils.push(instructions, 0); -// AsmOpUtils.arrayLoad(instructions, AsmOpUtils.OBJECT_TYPE); -// AsmOpUtils.checkCast(instructions, Type.getObjectType(methodInsnNode.owner)); -// } -// -// for(int i = 0; i < argumentTypes.length; ++i) { -// AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_ARRAY_TYPE, invokeArgsVariableNode.index); -// AsmOpUtils.push(instructions, i + (isStatic ? 0 : 1)); -// AsmOpUtils.arrayLoad(instructions, AsmOpUtils.OBJECT_TYPE); -// // TODO 这里直接 unbox 就可以了??unbox里带有 check cast -// if(AsmOpUtils.needBox(argumentTypes[i])) { -// AsmOpUtils.unbox(instructions, argumentTypes[i]); -// }else { -// AsmOpUtils.checkCast(instructions, argumentTypes[i]); -// } -// } - - }else { - throw new IllegalArgumentException("location is not a InvokeLocation, location: " + location); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - throw new UnsupportedOperationException("InvokeLocation saver do not support getType()"); - } - - }; - } - - return stackSaver; - } - - @Override - public MethodInsnNode methodInsnNode() { - return (MethodInsnNode) insnNode; - } - - } - - /** - * location identifying a synchronization trigger point - */ - public static class SyncEnterLocation extends Location { - /** - * count identifying which synchronization should be taken as the trigger point. - * if not specified as a parameter this defaults to the first synchronization. - */ - private int count; - - public SyncEnterLocation(AbstractInsnNode insnNode, int count, boolean whenComplete) { - super(insnNode, whenComplete); - this.count = count; - this.whenComplete = whenComplete; - this.stackNeedSave = !whenComplete; - } - - public LocationType getLocationType() { - if (whenComplete) { - return LocationType.SYNC_ENTER_COMPLETED; - } else { - return LocationType.SYNC_ENTER; - } - } - - @Override - public StackSaver getStackSaver() { - return new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode variableNode = bindingContext.getMethodProcessor().initMonitorVariableNode(); - AsmOpUtils.storeVar(instructions, AsmOpUtils.OBJECT_TYPE, variableNode.index); - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode variableNode = bindingContext.getMethodProcessor().initMonitorVariableNode(); - AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_TYPE, variableNode.index); - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.OBJECT_TYPE; - } - - }; - } - } - - /** - * location identifying a synchronization trigger point - */ - public static class SyncExitLocation extends Location { - /** - * count identifying which synchronization should be taken as the trigger point. - * if not specified as a parameter this defaults to the first synchronization. - */ - private int count; - - public SyncExitLocation(AbstractInsnNode insnNode, int count, boolean whenComplete) { - super(insnNode, whenComplete); - this.count = count; - this.whenComplete = whenComplete; - this.stackNeedSave = !whenComplete; - } - - public LocationType getLocationType() { - if (whenComplete) { - return LocationType.SYNC_ENTER_COMPLETED; - } else { - return LocationType.SYNC_ENTER; - } - } - - @Override - public StackSaver getStackSaver() { - return new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode variableNode = bindingContext.getMethodProcessor().initMonitorVariableNode(); - AsmOpUtils.storeVar(instructions, AsmOpUtils.OBJECT_TYPE, variableNode.index); - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode variableNode = bindingContext.getMethodProcessor().initMonitorVariableNode(); - AsmOpUtils.loadVar(instructions, AsmOpUtils.OBJECT_TYPE, variableNode.index); - } - - @Override - public Type getType(BindingContext bindingContext) { - return AsmOpUtils.OBJECT_TYPE; - } - - }; - } - } - - /** - * location identifying a throw trigger point - */ - public static class ThrowLocation extends Location { - /** - * count identifying which throw operation should be taken as the trigger point. - * if not specified as a parameter this defaults to the first throw. - */ - private int count; - - public ThrowLocation(AbstractInsnNode insnNode, int count) { - super(insnNode); - this.count = count; - stackNeedSave = true; - } - - @Override - public boolean canChangeByReturn() { - return true; - } - - public LocationType getLocationType() { - return LocationType.THROW; - } - - public StackSaver getStackSaver() { - StackSaver stackSaver = new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode throwVariableNode = bindingContext.getMethodProcessor().initThrowVariableNode(); - AsmOpUtils.storeVar(instructions, Type.getType(Throwable.class), throwVariableNode.index); - - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode throwVariableNode = bindingContext.getMethodProcessor().initThrowVariableNode(); - AsmOpUtils.loadVar(instructions, Type.getType(Throwable.class), throwVariableNode.index); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(Throwable.class); - } - - }; - return stackSaver; - } - } - - /** - * location identifying a method exit trigger point - */ - public static class ExitLocation extends Location { - - public ExitLocation(AbstractInsnNode insnNode) { - super(insnNode); - stackNeedSave = true; - } - - @Override - public boolean canChangeByReturn() { - return true; - } - - public LocationType getLocationType() { - return LocationType.EXIT; - } - - public StackSaver getStackSaver() { - StackSaver stackSaver = new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - Type returnType = bindingContext.getMethodProcessor().getReturnType(); - if(!returnType.equals(Type.VOID_TYPE)) { - LocalVariableNode returnVariableNode = bindingContext.getMethodProcessor().initReturnVariableNode(); - AsmOpUtils.storeVar(instructions, returnType, returnVariableNode.index); - } - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - Type returnType = bindingContext.getMethodProcessor().getReturnType(); - if(!returnType.equals(Type.VOID_TYPE)) { - LocalVariableNode returnVariableNode = bindingContext.getMethodProcessor().initReturnVariableNode(); - AsmOpUtils.loadVar(instructions, returnType, returnVariableNode.index); - } - } - - @Override - public Type getType(BindingContext bindingContext) { - return bindingContext.getMethodProcessor().getReturnType(); - } - - }; - return stackSaver; - } - - } - - /** - * location identifying a method exceptional exit trigger point - */ - public static class ExceptionExitLocation extends Location{ - public ExceptionExitLocation(AbstractInsnNode insnNode) { - super(insnNode, true); - stackNeedSave = true; - } - - public LocationType getLocationType() { - return LocationType.EXCEPTION_EXIT; - } - - public StackSaver getStackSaver() { - StackSaver stackSaver = new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode throwVariableNode = bindingContext.getMethodProcessor().initThrowVariableNode(); - AsmOpUtils.storeVar(instructions, Type.getType(Throwable.class), throwVariableNode.index); - - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode throwVariableNode = bindingContext.getMethodProcessor().initThrowVariableNode(); - AsmOpUtils.loadVar(instructions, Type.getType(Throwable.class), throwVariableNode.index); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(Throwable.class); - } - - }; - return stackSaver; - } - } - - /** - * location identifying a method exceptional exit trigger point - */ - public static class InvokeExceptionExitLocation extends Location implements MethodInsnNodeWare { - private MethodInsnNode methodInsnNode; - - public InvokeExceptionExitLocation(MethodInsnNode methodInsnNode, AbstractInsnNode insnNode) { - super(insnNode, true); - stackNeedSave = true; - this.methodInsnNode = methodInsnNode; - } - - public LocationType getLocationType() { - return LocationType.INVOKE_EXCEPTION_EXIT; - } - - public StackSaver getStackSaver() { - StackSaver stackSaver = new StackSaver() { - - @Override - public void store(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode throwVariableNode = bindingContext.getMethodProcessor().initThrowVariableNode(); - AsmOpUtils.storeVar(instructions, Type.getType(Throwable.class), throwVariableNode.index); - - } - - @Override - public void load(InsnList instructions, BindingContext bindingContext) { - LocalVariableNode throwVariableNode = bindingContext.getMethodProcessor().initThrowVariableNode(); - AsmOpUtils.loadVar(instructions, Type.getType(Throwable.class), throwVariableNode.index); - } - - @Override - public Type getType(BindingContext bindingContext) { - return Type.getType(Throwable.class); - } - - }; - return stackSaver; - } - - @Override - public MethodInsnNode methodInsnNode() { - return methodInsnNode; - } - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LocationMatcher.java deleted file mode 100644 index c37746244..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LocationMatcher.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.List; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; - -public interface LocationMatcher { - - public List match(MethodProcessor methodProcessor); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LocationType.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LocationType.java deleted file mode 100644 index b2d0b1c61..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/LocationType.java +++ /dev/null @@ -1,91 +0,0 @@ - -package com.taobao.arthas.bytekit.asm.location; - -public enum LocationType { - /** - * user define. - */ - USER_DEFINE, - - /** - * method enter. - * - */ - ENTER, - /** - * line number. - * - */ - LINE, - /** - * field read operation. - * - */ - READ, - /** - * field read operation. - */ - READ_COMPLETED, - /** - * field write operation. - * - */ - WRITE, - /** - * field write operation. - * - */ - WRITE_COMPLETED, - /** - * method invoke operation - * - */ - INVOKE, - /** - * method invoke operation - * - */ - INVOKE_COMPLETED, - - /** - * method invoke exception - */ - INVOKE_EXCEPTION_EXIT, - /** - * synchronize operation - * - */ - SYNC_ENTER, - /** - * synchronize operation - * - */ - SYNC_ENTER_COMPLETED, - - /** - * synchronize operation - * - */ - SYNC_EXIT, - /** - * synchronize operation - * - */ - SYNC_EXIT_COMPLETED, - - /** - * throw - */ - THROW, - - /** - * return - */ - EXIT, - - /** - * add try/catch - */ - EXCEPTION_EXIT; - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/MatchResult.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/MatchResult.java deleted file mode 100644 index 77c31c016..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/MatchResult.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.List; - -public class MatchResult { - - List locations; - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/MethodInsnNodeWare.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/MethodInsnNodeWare.java deleted file mode 100644 index d3d0d6fe7..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/MethodInsnNodeWare.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; - -public interface MethodInsnNodeWare { - - public MethodInsnNode methodInsnNode(); -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/SyncExitLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/SyncExitLocationMatcher.java deleted file mode 100644 index bd38e7de4..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/SyncExitLocationMatcher.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.SyncEnterLocation; - -public class SyncExitLocationMatcher implements LocationMatcher { - - private int count; - - boolean whenComplete; - - public SyncExitLocationMatcher(int count, boolean whenComplete) { - this.count = count; - this.whenComplete = whenComplete; - } - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - int matchedCount = 0; - while (insnNode != null) { - if (insnNode instanceof InsnNode) { - InsnNode node = (InsnNode) insnNode; - if (node.getOpcode() == Opcodes.MONITOREXIT) { - ++matchedCount; - if (count <= 0 || count == matchedCount) { - SyncEnterLocation location = new SyncEnterLocation(node, matchedCount, whenComplete); - locations.add(location); - } - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/SyncLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/SyncLocationMatcher.java deleted file mode 100644 index 119573126..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/SyncLocationMatcher.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.SyncEnterLocation; - -public class SyncLocationMatcher implements LocationMatcher { - - private int count; - - boolean whenComplete; - - int opcode; - - public SyncLocationMatcher(int opcode, int count, boolean whenComplete) { - if (!(Opcodes.MONITORENTER == opcode || Opcodes.MONITOREXIT == opcode)) { - throw new IllegalArgumentException( - "SyncLocationMatcher only support Opcodes.MONITORENTER or Opcodes.MONITOREXIT."); - } - this.opcode = opcode; - this.count = count; - this.whenComplete = whenComplete; - } - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - int matchedCount = 0; - while (insnNode != null) { - if (insnNode instanceof InsnNode) { - InsnNode node = (InsnNode) insnNode; - if (node.getOpcode() == opcode) { - ++matchedCount; - if (count <= 0 || count == matchedCount) { - SyncEnterLocation location = new SyncEnterLocation(node, matchedCount, whenComplete); - locations.add(location); - } - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ThrowLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ThrowLocationMatcher.java deleted file mode 100644 index 3b74e9207..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/ThrowLocationMatcher.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.location.Location.ThrowLocation; - -public class ThrowLocationMatcher implements LocationMatcher { - - public ThrowLocationMatcher(int count) { - this.count = count; - } - - /** - * count identifying which invocation should be taken as the trigger point. - * if not specified as a parameter this defaults to the first invocation. - */ - private int count; - - @Override - public List match(MethodProcessor methodProcessor) { - List locations = new ArrayList(); - AbstractInsnNode insnNode = methodProcessor.getEnterInsnNode(); - - int matchedCount = 0; - while (insnNode != null) { - if (insnNode instanceof InsnNode) { - InsnNode node = (InsnNode) insnNode; - if (node.getOpcode() == Opcodes.ATHROW) { - ++matchedCount; - if (count <= 0 || count == matchedCount) { - ThrowLocation location = new ThrowLocation(node, matchedCount); - locations.add(location); - } - } - } - insnNode = insnNode.getNext(); - } - - return locations; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/VariableAccessLocationMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/VariableAccessLocationMatcher.java deleted file mode 100644 index 590f40a77..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/VariableAccessLocationMatcher.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location; - -import java.util.List; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; - -public class VariableAccessLocationMatcher extends AccessLocationMatcher { - - /** - * the name of the variable being accessed at the point where the trigger - * point should be inserted - */ - private String variableName; - - /** - * flag which is true if the name is a method parameter index such as $0, $1 - * etc otherwise false - */ - private boolean isIndex; - - - protected VariableAccessLocationMatcher(String variablename, int count, int flags, boolean whenComplete) { - super(count, flags, whenComplete); - this.variableName = variablename; - isIndex = variablename.matches("[0-9]+"); - } - - @Override - public List match(MethodProcessor methodProcessor) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/DefaultLocationFilter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/DefaultLocationFilter.java deleted file mode 100644 index 32e73f6ab..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/DefaultLocationFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.taobao.arthas.bytekit.asm.location.LocationType; -import com.taobao.arthas.bytekit.utils.MatchUtils; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class DefaultLocationFilter implements LocationFilter { - -// private List signatures; -// -// public DefaultLocationFilter(List signatures) { -// this.signatures = signatures; -// } - - @Override - public boolean allow(AbstractInsnNode insnNode, LocationType locationType, boolean complete) { - return true; - } - -// @Override -// public boolean allow(String signature) { -// for (String s : signatures) { -// if (MatchUtils.wildcardMatch(signature, s)) { -// return false; -// } -// } -// -// return true; -// } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/GroupLocationFilter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/GroupLocationFilter.java deleted file mode 100644 index 9ee6bce64..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/GroupLocationFilter.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.taobao.arthas.bytekit.asm.location.LocationType; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class GroupLocationFilter implements LocationFilter { - - List filters = new ArrayList(); - - public GroupLocationFilter(LocationFilter... filters) { - for (LocationFilter filter : filters) { - this.filters.add(filter); - } - } - - public void addFilter(LocationFilter filter) { - this.filters.add(filter); - } - - @Override - public boolean allow(AbstractInsnNode insnNode, LocationType locationType, boolean complete) { - for (LocationFilter filter : filters) { - if (filter.allow(insnNode, locationType, complete)) { - return true; - } - } - return false; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeCheckLocationFilter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeCheckLocationFilter.java deleted file mode 100644 index 806f62bfd..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeCheckLocationFilter.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.taobao.arthas.bytekit.asm.location.LocationType; - -/** - * - * 检查某个 AbstractInsnNode 的前面是否有某个函数调用,如果有,则认为这个location是已被处理过的 - * - * @author hengyunabc 2020-05-04 - * - */ -public class InvokeCheckLocationFilter implements LocationFilter { - - private String owner; - private String methodName; - private LocationType locationType; - - public InvokeCheckLocationFilter(String owner, String methodName, LocationType locationType) { - this.owner = owner; - this.methodName = methodName; - this.locationType = locationType; - } - - @Override - public boolean allow(AbstractInsnNode insnNode, LocationType locationType, boolean complete) { - // 只检查自己对应的 LocationType - if (!this.locationType.equals(locationType)) { - return false; - } - - MethodInsnNode methodInsnNode = findMethodInsnNode(insnNode, complete); - if (methodInsnNode != null) { - if (methodInsnNode.owner.equals(this.owner) && methodInsnNode.name.equals(this.methodName)) { - return false; - } - } - - return true; - } - - private MethodInsnNode findMethodInsnNode(AbstractInsnNode insnNode, boolean complete) { - if (complete) { - while (insnNode != null) { - insnNode = insnNode.getNext(); - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - return methodInsnNode; - } - } - } else { - while (insnNode != null) { - insnNode = insnNode.getPrevious(); - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - return methodInsnNode; - } - } - } - return null; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeContainLocationFilter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeContainLocationFilter.java deleted file mode 100644 index af59fbefe..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeContainLocationFilter.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.taobao.arthas.bytekit.asm.location.LocationType; - -/** - * - * 检查整个method里,是否有某个函数调用。用于检查 enter/exit/exception exit - * - * @author hengyunabc 2020-05-04 - * - */ -public class InvokeContainLocationFilter implements LocationFilter { - - private String owner; - private String methodName; - private LocationType locationType; - - public InvokeContainLocationFilter(String owner, String methodName, LocationType locationType) { - this.owner = owner; - this.methodName = methodName; - this.locationType = locationType; - } - - @Override - public boolean allow(AbstractInsnNode insnNode, LocationType locationType, boolean complete) { - // 只检查自己对应的 LocationType - if (!this.locationType.equals(locationType)) { - return false; - } - - MethodInsnNode methodInsnNode = findMethodInsnNode(insnNode); - if (methodInsnNode != null) { - if (methodInsnNode.owner.equals(this.owner) && methodInsnNode.name.equals(this.methodName)) { - return false; - } - } - - return true; - } - - private MethodInsnNode findMethodInsnNode(AbstractInsnNode insnNode) { - - AbstractInsnNode current = insnNode; - while (current != null) { - current = current.getNext(); - if (current instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) current; - if (methodInsnNode.owner.equals(this.owner) && methodInsnNode.name.equals(this.methodName)) { - return methodInsnNode; - } - } - } - current = insnNode; - while (current != null) { - current = current.getPrevious(); - if (current instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) current; - if (methodInsnNode.owner.equals(this.owner) && methodInsnNode.name.equals(this.methodName)) { - return methodInsnNode; - } - } - } - return null; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/LocationFilter.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/LocationFilter.java deleted file mode 100644 index ac754b5a3..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/location/filter/LocationFilter.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.taobao.arthas.bytekit.asm.location.LocationType; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public interface LocationFilter { - - public boolean allow(AbstractInsnNode insnNode, LocationType locationType, boolean complete); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/matcher/ClassMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/matcher/ClassMatcher.java deleted file mode 100644 index e9a4b4fbc..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/matcher/ClassMatcher.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.taobao.arthas.bytekit.asm.matcher; - -public interface ClassMatcher { - - boolean match(String name, ClassLoader classLoader); - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/matcher/MethodMatcher.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/matcher/MethodMatcher.java deleted file mode 100644 index 2edc72486..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/asm/matcher/MethodMatcher.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.taobao.arthas.bytekit.asm.matcher; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -public interface MethodMatcher { - - boolean match(String className, MethodNode methodNode); -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AgentUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AgentUtils.java deleted file mode 100644 index 84ee37e82..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AgentUtils.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.lang.instrument.ClassDefinition; -import java.lang.instrument.ClassFileTransformer; -import java.lang.instrument.IllegalClassFormatException; -import java.lang.instrument.Instrumentation; -import java.lang.instrument.UnmodifiableClassException; -import java.security.ProtectionDomain; - -import net.bytebuddy.agent.ByteBuddyAgent; - -public class AgentUtils { - - private static class InstrumentationHolder { - static final Instrumentation instance = ByteBuddyAgent.install(); - } - - public static Instrumentation install() { - return InstrumentationHolder.instance; - - } - - public static void redefine(Class clazz, byte[] classFile) - throws ClassNotFoundException, UnmodifiableClassException { - ClassDefinition classDefinition = new ClassDefinition(clazz, classFile); - InstrumentationHolder.instance.redefineClasses(classDefinition); - } - - public static void reTransform(Class clazz, byte[] classFile) throws UnmodifiableClassException { - - SimpleClassFileTransformer transformer = new SimpleClassFileTransformer(clazz.getClassLoader(), clazz.getName(), - classFile); - InstrumentationHolder.instance.addTransformer(transformer, true); - - InstrumentationHolder.instance.retransformClasses(clazz); - InstrumentationHolder.instance.removeTransformer(transformer); - } - - public static class SimpleClassFileTransformer implements ClassFileTransformer { - private byte[] classBuffer; - private ClassLoader classLoader; - private String className; - - public SimpleClassFileTransformer(ClassLoader classLoader, String className, byte[] classBuffer) { - this.classLoader = classLoader; - this.className = className.replace('.', '/'); - this.classBuffer = classBuffer; - } - - @Override - public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, - ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { - - if (this.classLoader == loader && className.equals(this.className)) { - return classBuffer; - } - - return null; - - } - - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AnnotationUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AnnotationUtils.java deleted file mode 100644 index 327b610a1..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AnnotationUtils.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -public class AnnotationUtils { - - public static A findAnnotation(Method method, Class annotationType) { - return method.getAnnotation(annotationType); - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmAnnotationUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmAnnotationUtils.java deleted file mode 100644 index 70d381d39..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmAnnotationUtils.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AnnotationNode; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class AsmAnnotationUtils { - - public static List queryAnnotationInfo(List annotations, String annotationType, - String key) { - List result = new ArrayList(); - if (annotations != null) { - for (AnnotationNode annotationNode : annotations) { - if (annotationNode.desc.equals(annotationType)) { - if (annotationNode.values != null) { - Iterator iterator = annotationNode.values.iterator(); - while (iterator.hasNext()) { - String name = (String) iterator.next(); - Object values = iterator.next(); - if (key.equals(name)) { - result.addAll((List) values); - } - } - } - } - } - } - return result; - } - - public static void addAnnotationInfo(List annotations, String annotationType, String key, - String value) { - - AnnotationNode annotationNode = null; - for (AnnotationNode tmp : annotations) { - if (tmp.desc.equals(annotationType)) { - annotationNode = tmp; - } - } - - if (annotationNode == null) { - annotationNode = new AnnotationNode(annotationType); - annotations.add(annotationNode); - } - - if (annotationNode.values == null) { - annotationNode.values = new ArrayList(); - } - - // 查找有没有对应的key - String name = null; - List values = null; - Iterator iterator = annotationNode.values.iterator(); - while (iterator.hasNext()) { - if (key.equals(iterator.next())) { - values = (List) iterator.next(); - } else { - iterator.next(); - } - } - if (values == null) { - values = new ArrayList(); - annotationNode.values.add(key); - annotationNode.values.add(values); - } - if (!values.contains(values)) { - values.add(value); - } - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmOpUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmOpUtils.java deleted file mode 100644 index 81f1a7f85..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmOpUtils.java +++ /dev/null @@ -1,463 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.Method; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FieldInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.IntInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LdcInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TypeInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.VarInsnNode; - -public class AsmOpUtils { - - private static final Type BYTE_TYPE = Type.getObjectType("java/lang/Byte"); - - private static final Type BOOLEAN_TYPE = Type.getObjectType("java/lang/Boolean"); - - private static final Type SHORT_TYPE = Type.getObjectType("java/lang/Short"); - - private static final Type CHARACTER_TYPE = Type.getObjectType("java/lang/Character"); - - private static final Type INTEGER_TYPE = Type.getObjectType("java/lang/Integer"); - - private static final Type FLOAT_TYPE = Type.getObjectType("java/lang/Float"); - - private static final Type LONG_TYPE = Type.getObjectType("java/lang/Long"); - - private static final Type DOUBLE_TYPE = Type.getObjectType("java/lang/Double"); - - public static final Type OBJECT_TYPE = Type.getObjectType("java/lang/Object"); - - public static final Type OBJECT_ARRAY_TYPE = Type.getType(Object[].class); - - public static final Type STRING_TYPE = Type.getObjectType("java/lang/String"); - - public static final Type STRING_ARRAY_TYPE = Type.getType(String[].class); - - private static final Type NUMBER_TYPE = Type.getObjectType("java/lang/Number"); - - private static final Method BOOLEAN_VALUE = Method.getMethod("boolean booleanValue()"); - - private static final Method CHAR_VALUE = Method.getMethod("char charValue()"); - - private static final Method BYTE_VALUE = Method.getMethod("byte byteValue()"); - - private static final Method SHORT_VALUE = Method.getMethod("short shortValue()"); - - private static final Method INT_VALUE = Method.getMethod("int intValue()"); - - private static final Method FLOAT_VALUE = Method.getMethod("float floatValue()"); - - private static final Method LONG_VALUE = Method.getMethod("long longValue()"); - - private static final Method DOUBLE_VALUE = Method.getMethod("double doubleValue()"); - - public static boolean isBoxType(final Type type) { - if (BYTE_TYPE.equals(type) || BOOLEAN_TYPE.equals(type) || SHORT_TYPE.equals(type) - || CHARACTER_TYPE.equals(type) || INTEGER_TYPE.equals(type) || FLOAT_TYPE.equals(type) - || LONG_TYPE.equals(type) || DOUBLE_TYPE.equals(type)) { - return true; - } - return false; - } - - public static Type getBoxedType(final Type type) { - switch (type.getSort()) { - case Type.BYTE: - return BYTE_TYPE; - case Type.BOOLEAN: - return BOOLEAN_TYPE; - case Type.SHORT: - return SHORT_TYPE; - case Type.CHAR: - return CHARACTER_TYPE; - case Type.INT: - return INTEGER_TYPE; - case Type.FLOAT: - return FLOAT_TYPE; - case Type.LONG: - return LONG_TYPE; - case Type.DOUBLE: - return DOUBLE_TYPE; - } - return type; - } - - public static Method getUnBoxMethod(final Type type) { - switch (type.getSort()) { - case Type.BYTE: - return BYTE_VALUE; - case Type.BOOLEAN: - return BOOLEAN_VALUE; - case Type.SHORT: - return SHORT_VALUE; - case Type.CHAR: - return CHAR_VALUE; - case Type.INT: - return INT_VALUE; - case Type.FLOAT: - return FLOAT_VALUE; - case Type.LONG: - return LONG_VALUE; - case Type.DOUBLE: - return DOUBLE_VALUE; - } - throw new IllegalArgumentException(type + " is not a primitive type."); - } - - public static void newInstance(final InsnList instructions, final Type type) { - instructions.add(new TypeInsnNode(Opcodes.NEW, type.getInternalName())); - } - - public static void push(InsnList insnList, final int value) { - if (value >= -1 && value <= 5) { - insnList.add(new InsnNode(Opcodes.ICONST_0 + value)); - } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { - insnList.add(new IntInsnNode(Opcodes.BIPUSH, value)); - } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { - insnList.add(new IntInsnNode(Opcodes.SIPUSH, value)); - } else { - insnList.add(new LdcInsnNode(value)); - } - } - - public static void push(InsnList insnList, final String value) { - if (value == null) { - insnList.add(new InsnNode(Opcodes.ACONST_NULL)); - } else { - insnList.add(new LdcInsnNode(value)); - } - } - - public static void pushNUll(InsnList insnList) { - insnList.add(new InsnNode(Opcodes.ACONST_NULL)); - } - - /** - * @see org.objectweb.asm.tree.LdcInsnNode#cst - * @param value - */ - public static void ldc(InsnList insnList, Object value) { - insnList.add(new LdcInsnNode(value)); - } - - public static void newArray(final InsnList insnList, final Type type) { - insnList.add(new TypeInsnNode(Opcodes.ANEWARRAY, type.getInternalName())); - } - - public static void dup(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP)); - } - - public static void dup2(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP2)); - } - - public static void dupX1(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP_X1)); - } - - public static void dupX2(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP_X2)); - } - - /** - * Generates a DUP2_X1 instruction. - */ - public static void dup2X1(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP2_X1)); - } - - /** - * Generates a DUP2_X2 instruction. - */ - public static void dup2X2(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.DUP2_X2)); - } - - - public static void pop(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.POP)); - } - - /** - * Generates a POP2 instruction. - */ - public static void pop2(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.POP2)); - } - - public static void swap(final InsnList insnList) { - insnList.add(new InsnNode(Opcodes.SWAP)); - } - - /** - * Generates the instructions to swap the top two stack values. - * - * @param prev - * type of the top - 1 stack value. - * @param type - * type of the top stack value. - */ - public static void swap(final InsnList insnList, final Type prev, final Type type) { - if (type.getSize() == 1) { - if (prev.getSize() == 1) { - swap(insnList); // same as dupX1(), pop(); - } else { - dupX2(insnList); - pop(insnList); - } - } else { - if (prev.getSize() == 1) { - dup2X1(insnList); - pop2(insnList); - } else { - dup2X2(insnList); - pop2(insnList); - } - } - } - - public static void box(final InsnList instructions, Type type) { - if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) { - return; - } - - if (type == Type.VOID_TYPE) { - // push null - instructions.add(new InsnNode(Opcodes.ACONST_NULL)); - } else { - Type boxed = getBoxedType(type); - // new instance. - newInstance(instructions, boxed); - if (type.getSize() == 2) { - // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o - // dupX2 - dupX2(instructions); - // dupX2 - dupX2(instructions); - // pop - pop(instructions); - } else { - // p -> po -> opo -> oop -> o - // dupX1 - dupX1(instructions); - // swap - swap(instructions); - } - invokeConstructor(instructions, boxed, new Method("", Type.VOID_TYPE, new Type[] { type })); - } - } - - public static void invokeConstructor(final InsnList instructions, final Type type, final Method method) { - String owner = type.getSort() == Type.ARRAY ? type.getDescriptor() : type.getInternalName(); - instructions - .add(new MethodInsnNode(Opcodes.INVOKESPECIAL, owner, method.getName(), method.getDescriptor(), false)); - } - - /** - * - * @param instructions - * @param type - * @see org.objectweb.asm.commons.GeneratorAdapter#unbox(Type) - */ - public static void unbox(final InsnList instructions, Type type) { - Type t = NUMBER_TYPE; - Method sig = null; - switch (type.getSort()) { - case Type.VOID: - return; - case Type.CHAR: - t = CHARACTER_TYPE; - sig = CHAR_VALUE; - break; - case Type.BOOLEAN: - t = BOOLEAN_TYPE; - sig = BOOLEAN_VALUE; - break; - case Type.DOUBLE: - sig = DOUBLE_VALUE; - break; - case Type.FLOAT: - sig = FLOAT_VALUE; - break; - case Type.LONG: - sig = LONG_VALUE; - break; - case Type.INT: - case Type.SHORT: - case Type.BYTE: - sig = INT_VALUE; - } - if (sig == null) { - instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, type.getInternalName())); - } else { - instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, t.getInternalName())); - instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, t.getInternalName(), sig.getName(), - sig.getDescriptor(), false)); - } - } - - public static boolean needBox(Type type) { - switch (type.getSort()) { - case Type.BYTE: - case Type.BOOLEAN: - case Type.SHORT: - case Type.CHAR: - case Type.INT: - case Type.FLOAT: - case Type.LONG: - case Type.DOUBLE: - return true; - } - return false; - } - - public static void getStatic(final InsnList insnList, final Type owner, final String name, final Type type) { - insnList.add(new FieldInsnNode(Opcodes.GETSTATIC, owner.getInternalName(), name, type.getDescriptor())); - } - - /** - * Generates the instruction to push the value of a non static field on the - * stack. - * - * @param owner - * the class in which the field is defined. - * @param name - * the name of the field. - * @param type - * the type of the field. - */ - public static void getField(final InsnList insnList, final Type owner, final String name, final Type type) { - insnList.add(new FieldInsnNode(Opcodes.GETFIELD, owner.getInternalName(), name, type.getDescriptor())); - } - - public static void arrayStore(final InsnList instructions, final Type type) { - instructions.add(new InsnNode(type.getOpcode(Opcodes.IASTORE))); - } - - public static void arrayLoad(final InsnList instructions, final Type type) { - instructions.add(new InsnNode(type.getOpcode(Opcodes.IALOAD))); - } - - - /** - * Generates the instruction to load 'this' on the stack. - * @see org.objectweb.asm.commons.GeneratorAdapter#loadThis() - * @param instructions - */ - public static void loadThis(final InsnList instructions) { - instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - } - - /** - * Generates the instructions to load all the method arguments on the stack, - * as a single object array. - * - * @see org.objectweb.asm.commons.GeneratorAdapter#loadArgArray() - */ - public static void loadArgArray(final InsnList instructions, MethodNode methodNode) { - boolean isStatic = AsmUtils.isStatic(methodNode); - Type[] argumentTypes = Type.getArgumentTypes(methodNode.desc); - push(instructions, argumentTypes.length); - newArray(instructions, OBJECT_TYPE); - for (int i = 0; i < argumentTypes.length; i++) { - dup(instructions); - push(instructions, i); - loadArg(isStatic, instructions, argumentTypes, i); - box(instructions, argumentTypes[i]); - arrayStore(instructions, OBJECT_TYPE); - } - } - - public static void loadArgs(final InsnList instructions, MethodNode methodNode) { - Type[] argumentTypes = Type.getArgumentTypes(methodNode.desc); - boolean isStatic = AsmUtils.isStatic(methodNode); - for (int i = 0; i < argumentTypes.length; i++) { - loadArg(isStatic, instructions, argumentTypes, i); - } - } - - public static void loadArg(boolean staticAccess, final InsnList instructions, Type[] argumentTypes, int i) { - final int index = getArgIndex(staticAccess, argumentTypes, i); - final Type type = argumentTypes[i]; - instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), index)); - } - - static int getArgIndex(boolean staticAccess, final Type[] argumentTypes, final int arg) { - int index = staticAccess ? 0 : 1; - for (int i = 0; i < arg; i++) { - index += argumentTypes[i].getSize(); - } - return index; - } - - public static void loadVar(final InsnList instructions, Type type, final int index) { - instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), index)); - } - - public static void storeVar(final InsnList instructions, Type type, final int index) { - instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ISTORE), index)); - } - - /** - * Generates a type dependent instruction. - * - * @param opcode - * the instruction's opcode. - * @param type - * the instruction's operand. - */ - private static void typeInsn(final InsnList instructions, final int opcode, final Type type) { - instructions.add(new TypeInsnNode(opcode, type.getInternalName())); - } - - /** - * Generates the instruction to check that the top stack value is of the - * given type. - * - * @param type - * a class or interface type. - */ - public static void checkCast(final InsnList instructions, final Type type) { - if (!type.equals(OBJECT_TYPE)) { - typeInsn(instructions, Opcodes.CHECKCAST, type); - } - } - - public static void throwException(final InsnList instructions) { - instructions.add(new InsnNode(Opcodes.ATHROW)); - } - - public static boolean isReturnCode(final int opcode) { - return opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN; - } - - public static List validVariables(List localVariables, - AbstractInsnNode currentInsnNode) { - List results = new ArrayList(); - - // find out current valid local variables - for (LocalVariableNode localVariableNode : localVariables) { - for (AbstractInsnNode iter = localVariableNode.start; iter != null - && (!iter.equals(localVariableNode.end)); iter = iter.getNext()) { - if (iter.equals(currentInsnNode)) { - results.add(localVariableNode); - break; - } - } - } - - return results; - } -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmUtils.java deleted file mode 100644 index 92b49fc4e..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/AsmUtils.java +++ /dev/null @@ -1,586 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.ClassReader; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassWriter; -import com.alibaba.arthas.deps.org.objectweb.asm.Label; -import com.alibaba.arthas.deps.org.objectweb.asm.MethodVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.ClassRemapper; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.JSRInlinerAdapter; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.Remapper; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FieldNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LocalVariableNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.TypeInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.util.ASMifier; -import com.alibaba.arthas.deps.org.objectweb.asm.util.TraceClassVisitor; -import com.taobao.arthas.bytekit.asm.ClassLoaderAwareClassWriter; - -/** - * - * @author hengyunabc - * - */ -public class AsmUtils { - - public static ClassNode loadClass(Class clazz) throws IOException { - String resource = clazz.getName().replace('.', '/') + ".class"; - InputStream is = clazz.getClassLoader().getResourceAsStream(resource); - ClassReader cr = new ClassReader(is); - ClassNode classNode = new ClassNode(); - cr.accept(classNode, ClassReader.SKIP_FRAMES); - return classNode; - } - - public static ClassNode toClassNode(byte[] classBytes) { - ClassReader reader = new ClassReader(classBytes); - ClassNode result = new ClassNode(Opcodes.ASM9); - reader.accept(result, ClassReader.SKIP_FRAMES); - return result; - } - - public static ClassReader toClassNode(byte[] classBytes, ClassNode classNode) { - ClassReader reader = new ClassReader(classBytes); - reader.accept(classNode, ClassReader.SKIP_FRAMES); - return reader; - } - - /** - * Generate class bytes from class node. - *
- * NOTE: must pass origin classReader for bytecode optimizations, avoiding JVM metaspace OOM. - * @param classNode - * @param classLoader - * @param classReader origin class reader - * @return - */ - public static byte[] toBytes(ClassNode classNode, ClassLoader classLoader, ClassReader classReader) { - int flags = ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS; - ClassWriter writer = new ClassLoaderAwareClassWriter(classReader, flags, classLoader); - classNode.accept(writer); - return writer.toByteArray(); - } - - public static byte[] toBytes(ClassNode classNode) { - ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - classNode.accept(writer); - return writer.toByteArray(); - } - - public static byte[] renameClass(byte[] classBytes, final String newClassName) { - final String internalName = newClassName.replace('.', '/'); - - ClassReader reader = new ClassReader(classBytes); - ClassWriter writer = new ClassWriter(0); - - class RenameRemapper extends Remapper { - private String className; - - @Override - public String map(String typeName) { - if (typeName.equals(className)) { - return internalName; - } - return super.map(typeName); - } - - public void setClassName(String className) { - this.className = className; - } - } - - final RenameRemapper renameRemapper = new RenameRemapper(); - ClassRemapper adapter = new ClassRemapper(writer, renameRemapper) { - @Override - public void visit(final int version, final int access, final String name, final String signature, - final String superName, final String[] interfaces) { - renameRemapper.setClassName(name); - super.visit(version, access, name, signature, superName, interfaces); - } - }; - reader.accept(adapter, ClassReader.EXPAND_FRAMES); - writer.visitEnd(); - return writer.toByteArray(); - } - - public static void replaceMethod(ClassNode classNode, MethodNode methodNode) { - for (int index = 0; index < classNode.methods.size(); ++index) { - MethodNode tmp = classNode.methods.get(index); - if (tmp.name.equals(methodNode.name) && tmp.desc.equals(methodNode.desc)) { - classNode.methods.set(index, methodNode); - } - } - } - - public static String toASMCode(byte[] bytecode) throws IOException { - return toASMCode(bytecode, true); - } - - public static String toASMCode(byte[] bytecode, boolean debug) throws IOException { - int flags = ClassReader.SKIP_DEBUG; - - if (debug) { - flags = 0; - } - - ClassReader cr = new ClassReader(new ByteArrayInputStream(bytecode)); - StringWriter sw = new StringWriter(); - cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(sw)), flags); - return sw.toString(); - } - - public static String toASMCode(ClassNode classNode) { - StringWriter sw = new StringWriter(); - classNode.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(sw))); - return sw.toString(); - } - - public static String toASMCode(MethodNode methodNode) { - ClassNode classNode = new ClassNode(); - classNode.methods.add(methodNode); - return toASMCode(classNode); - } - - public static MethodNode newMethodNode(MethodNode source) { - return new MethodNode(Opcodes.ASM9, source.access, source.name, source.desc, source.signature, - source.exceptions.toArray(new String[source.exceptions.size()])); - } - - public static MethodNode removeJSRInstructions(MethodNode subjectMethod) { - MethodNode result = newMethodNode(subjectMethod); - subjectMethod.accept(new JSRInlinerAdapter(result, subjectMethod.access, subjectMethod.name, subjectMethod.desc, - subjectMethod.signature, - subjectMethod.exceptions.toArray(new String[subjectMethod.exceptions.size()]))); - return result; - } - - public static ClassNode removeJSRInstructions(ClassNode classNode) { - ClassNode result = new ClassNode(Opcodes.ASM9); - classNode.accept(new ClassVisitor(Opcodes.ASM9, result) { - @Override - public MethodVisitor visitMethod(int access, String name, String desc, String signature, - String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); - return new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions); - } - }); - return result; - } - - public static MethodNode removeLineNumbers(MethodNode methodNode) { - MethodNode result = newMethodNode(methodNode); - methodNode.accept(new MethodVisitor(Opcodes.ASM9, result) { - public void visitLineNumber(int line, Label start) { - } - }); - return result; - } - - public static MethodNode findFirstMethod(Collection methodNodes, String name) { - for (MethodNode methodNode : methodNodes) { - if (methodNode.name.equals(name)) { - return methodNode; - } - } - return null; - } - - public static List findMethods(Collection methodNodes, String name) { - List result = new ArrayList(); - for (MethodNode methodNode : methodNodes) { - if (methodNode.name.equals(name)) { - result.add(methodNode); - } - } - return result; - } - - public static MethodNode findMethod(Collection methodNodes, MethodNode target) { - return findMethod(methodNodes, target.name, target.desc); - } - - public static MethodNode findMethod(Collection methodNodes, String name, String desc) { - for (MethodNode methodNode : methodNodes) { - if (methodNode.name.equals(name) && methodNode.desc.equals(desc)) { - return methodNode; - } - } - return null; - } - - public static AbstractInsnNode findInitConstructorInstruction(MethodNode methodNode) { - int nested = 0; - for (AbstractInsnNode insnNode = methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode - .getNext()) { - if (insnNode instanceof TypeInsnNode) { - if (insnNode.getOpcode() == Opcodes.NEW) { - // new object(). - nested++; - } - } else if (insnNode instanceof MethodInsnNode) { - final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - if (methodInsnNode.getOpcode() == Opcodes.INVOKESPECIAL && methodInsnNode.name.equals("")) { - if (--nested < 0) { - // find this() or super(). - return insnNode.getNext(); - } - } - } - } - - return null; - } - - public static List findMethodInsnNodeWithPrefix(MethodNode methodNode, String prefix) { - List result = new ArrayList(); - for (AbstractInsnNode insnNode = methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode - .getNext()) { - if (insnNode instanceof MethodInsnNode) { - final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - if(methodInsnNode.name.startsWith(prefix)) { - result.add(methodInsnNode); - } - } - } - return result; - } - - public static List findMethodInsnNode(MethodNode methodNode, String owner, String name) { - List result = new ArrayList(); - for (AbstractInsnNode insnNode = methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode - .getNext()) { - if (insnNode instanceof MethodInsnNode) { - final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - if (methodInsnNode.owner.equals(owner) && methodInsnNode.name.equals(name)) { - result.add(methodInsnNode); - } - } - } - return result; - } - public static List findMethodInsnNode(MethodNode methodNode, String owner, String name, - String desc) { - List result = new ArrayList(); - for (AbstractInsnNode insnNode = methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode - .getNext()) { - if (insnNode instanceof MethodInsnNode) { - final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - if (methodInsnNode.owner.equals(owner) && methodInsnNode.name.equals(name) - && methodInsnNode.desc.equals(desc)) { - result.add(methodInsnNode); - } - } - } - return result; - } - - public static boolean containsMethodInsnNode(MethodNode methodNode, String owner, String name) { - for (AbstractInsnNode insnNode = methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode - .getNext()) { - if (insnNode instanceof MethodInsnNode) { - final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - if (methodInsnNode.owner.equals(owner) && methodInsnNode.name.equals(name)) { - return true; - } - } - } - return false; - } - - public static boolean isStatic(MethodNode methodNode) { - return (methodNode.access & Opcodes.ACC_STATIC) != 0; - } - - public static boolean isStatic(MethodInsnNode methodInsnNode) { - return methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC; - } - - - public static boolean isConstructor(MethodNode methodNode) { - return methodNode.name != null && methodNode.name.equals(""); - } - - - public String[] getParameterNames(MethodNode methodNode) { - Type[] argumentTypes = Type.getArgumentTypes(methodNode.desc); - if (argumentTypes.length == 0) { - return new String[0]; - } - - final List localVariableNodes = methodNode.localVariables; - int localVariableStartIndex = 1; - if (isStatic(methodNode)) { - // static method is none this. - localVariableStartIndex = 0; - } - - if (localVariableNodes == null || localVariableNodes.size() <= localVariableStartIndex || - (argumentTypes.length + localVariableStartIndex) > localVariableNodes.size()) { - // make simple argument names. - final String[] names = new String[argumentTypes.length]; - for (int i = 0; i < argumentTypes.length; i++) { - final String className = argumentTypes[i].getClassName(); - if (className != null) { - final int findIndex = className.lastIndexOf('.'); - if (findIndex == -1) { - names[i] = className; - } else { - names[i] = className.substring(findIndex + 1); - } - } else { - names[i] = argumentTypes[i].getDescriptor(); - } - } - return names; - } - - // sort by index. - Collections.sort(localVariableNodes, new Comparator() { - - @Override - public int compare(LocalVariableNode o1, LocalVariableNode o2) { - return o1.index - o2.index; - } - }); - String[] names = new String[argumentTypes.length]; - - for (int i = 0; i < argumentTypes.length; i++) { - final String name = localVariableNodes.get(localVariableStartIndex++).name; - if (name != null) { - names[i] = name; - } else { - names[i] = ""; - } - } - - return names; - } - - public static MethodNode copy(MethodNode source) { - MethodNode result = newMethodNode(source); - source.accept(result); - return result; - } - - public static ClassNode copy(ClassNode source) { - ClassNode result = new ClassNode(Opcodes.ASM9); - source.accept(new ClassVisitor(Opcodes.ASM9, result) { - @Override - public MethodVisitor visitMethod(int access, String name, String desc, String signature, - String[] exceptions) { - MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); - return new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions); - } - }); - return result; - } - - - public static String methodDeclaration(MethodInsnNode methodInsnNode) { - StringBuilder sb = new StringBuilder(128); - - int opcode = methodInsnNode.getOpcode(); - if(opcode == Opcodes.INVOKESTATIC) { - sb.append("static "); - } - Type methodType = Type.getMethodType(methodInsnNode.desc); - Type ownerType = Type.getObjectType(methodInsnNode.owner); - - //skip constructor return type - if(methodInsnNode.name.equals("")) { - sb.append(ownerType.getClassName()); - }else { - sb.append(methodType.getReturnType().getClassName()).append(' '); - sb.append(methodInsnNode.name); - } - - sb.append('('); - Type[] argumentTypes = methodType.getArgumentTypes(); - for(int i = 0 ; i < argumentTypes.length; ++i) { - sb.append(argumentTypes[i].getClassName()); - if(i != argumentTypes.length - 1) { - sb.append(", "); - } - } - sb.append(')'); - return sb.toString(); - - } - - public static String methodDeclaration(Type owner, MethodNode methodNode) { - int access = methodNode.access; - StringBuilder sb = new StringBuilder(128); - -// int ACC_PUBLIC = 0x0001; // class, field, method -// int ACC_PRIVATE = 0x0002; // class, field, method -// int ACC_PROTECTED = 0x0004; // class, field, method -// int ACC_STATIC = 0x0008; // field, method -// int ACC_FINAL = 0x0010; // class, field, method, parameter -// int ACC_SUPER = 0x0020; // class -// int ACC_SYNCHRONIZED = 0x0020; // method -// int ACC_OPEN = 0x0020; // module -// int ACC_TRANSITIVE = 0x0020; // module requires -// int ACC_VOLATILE = 0x0040; // field -// int ACC_BRIDGE = 0x0040; // method -// int ACC_STATIC_PHASE = 0x0040; // module requires -// int ACC_VARARGS = 0x0080; // method -// int ACC_TRANSIENT = 0x0080; // field -// int ACC_NATIVE = 0x0100; // method -// int ACC_INTERFACE = 0x0200; // class -// int ACC_ABSTRACT = 0x0400; // class, method -// int ACC_STRICT = 0x0800; // method -// int ACC_SYNTHETIC = 0x1000; // class, field, method, parameter, module * -// int ACC_ANNOTATION = 0x2000; // class -// int ACC_ENUM = 0x4000; // class(?) field inner -// int ACC_MANDATED = 0x8000; // parameter, module, module * -// int ACC_MODULE = 0x8000; // class - - if((access & Opcodes.ACC_PUBLIC) != 0) { - sb.append("public "); - } - if((access & Opcodes.ACC_PRIVATE) != 0) { - sb.append("private "); - } - if((access & Opcodes.ACC_PROTECTED) != 0) { - sb.append("protected "); - } - if((access & Opcodes.ACC_STATIC) != 0) { - sb.append("static "); - } - - if((access & Opcodes.ACC_FINAL) != 0) { - sb.append("final "); - } - if((access & Opcodes.ACC_SYNCHRONIZED) != 0) { - sb.append("synchronized "); - } - if((access & Opcodes.ACC_NATIVE) != 0) { - sb.append("native "); - } - if((access & Opcodes.ACC_ABSTRACT) != 0) { - sb.append("abstract "); - } - - Type methodType = Type.getMethodType(methodNode.desc); - - //skip constructor return type - if(methodNode.name.equals("")) { - sb.append(owner.getClassName()); - }else { - sb.append(methodType.getReturnType().getClassName()).append(' '); - sb.append(methodNode.name); - } - - sb.append('('); - Type[] argumentTypes = methodType.getArgumentTypes(); - for(int i = 0 ; i < argumentTypes.length; ++i) { - sb.append(argumentTypes[i].getClassName()); - if(i != argumentTypes.length - 1) { - sb.append(", "); - } - } - sb.append(')'); - if(methodNode.exceptions != null) { - int exceptionSize = methodNode.exceptions.size(); - if( exceptionSize > 0) { - sb.append(" throws"); - for(int i = 0; i < exceptionSize; ++i) { - sb.append(' '); - sb.append(Type.getObjectType(methodNode.exceptions.get(i)).getClassName()); - if(i != exceptionSize -1) { - sb.append(','); - } - } - } - - } - - return sb.toString(); - } - - public static FieldNode findField(List fields, String name) { - for(FieldNode field : fields) { - if(field.name.equals(name)) { - return field; - } - } - return null; - } - - public static void addField(ClassNode classNode, FieldNode fieldNode) { - // TODO 检查是否有重复? - classNode.fields.add(fieldNode); - } - - public static void addMethod(ClassNode classNode, MethodNode methodNode) { - classNode.methods.add(methodNode); - } - - // TODO 是否真的 unique 了? - public static String uniqueNameForMethod(String className, String methodName, String desc) { - StringBuilder result = new StringBuilder(128); - result.append(cleanClassName(className)).append('_').append(methodName); - for(Type arg : Type.getMethodType(desc).getArgumentTypes()) { - result.append('_').append(cleanClassName(arg.getClassName())); - } - return result.toString(); - } - - private static String cleanClassName(String className) { - char[] charArray = className.toCharArray(); - int length = charArray.length; - for(int i = 0 ; i < length; ++i) { - switch( charArray[i]) { - case '[' : - case ']' : - case '<' : - case '>' : - case ';' : - case '/' : - case '.' : - charArray[i] = '_'; - break; - } - } - return new String(charArray); - } - - /** - * Java ClassFile versions (the minor version is stored in the 16 most - * significant bits, and the major version in the 16 least significant bits). - * @see com.alibaba.arthas.deps.org.objectweb.asm.Opcodes#V_PREVIEW - * @param version - * @return - */ - public static int getMajorVersion(int version) { - return 0x0000FFFF & version; - } - - /** - * 替换掉完整 version里的 major version - * - * @param version - * @param majorVersion - * @return - */ - public static int setMajorVersion(int version, int majorVersion) { - return (version & 0xFFFF0000) | majorVersion; - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/ClassLoaderUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/ClassLoaderUtils.java deleted file mode 100644 index 8f5a78a9a..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/ClassLoaderUtils.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.lang.reflect.Field; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; - -import sun.misc.Unsafe; - - -/** - * - * @author hengyunabc 2017-10-12 - * - */ -public class ClassLoaderUtils { - @SuppressWarnings({ "restriction", "unchecked" }) - public static URL[] getUrls(ClassLoader classLoader) { - if (classLoader instanceof URLClassLoader) { - return ((URLClassLoader) classLoader).getURLs(); - } - - // jdk9 - if (classLoader.getClass().getName().startsWith("jdk.internal.loader.ClassLoaders$")) { - try { - Field field = Unsafe.class.getDeclaredField("theUnsafe"); - field.setAccessible(true); - Unsafe unsafe = (Unsafe) field.get(null); - - // jdk.internal.loader.ClassLoaders.AppClassLoader.ucp - Field ucpField = classLoader.getClass().getDeclaredField("ucp"); - long ucpFieldOffset = unsafe.objectFieldOffset(ucpField); - Object ucpObject = unsafe.getObject(classLoader, ucpFieldOffset); - - // jdk.internal.loader.URLClassPath.path - Field pathField = ucpField.getType().getDeclaredField("path"); - long pathFieldOffset = unsafe.objectFieldOffset(pathField); - ArrayList path = (ArrayList) unsafe.getObject(ucpObject, pathFieldOffset); - - return path.toArray(new URL[path.size()]); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - return null; - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/Decompiler.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/Decompiler.java deleted file mode 100644 index 1a815208a..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/Decompiler.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -import org.benf.cfr.reader.api.CfrDriver; -import org.benf.cfr.reader.api.OutputSinkFactory; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.alibaba.arthas.deps.org.objectweb.asm.util.Printer; -import com.alibaba.arthas.deps.org.objectweb.asm.util.Textifier; -import com.alibaba.arthas.deps.org.objectweb.asm.util.TraceClassVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.util.TraceMethodVisitor; -import com.taobao.arthas.common.FileUtils; - -/** - * TODO com.taobao.arthas.core.util.Decompiler - * @author hengyunabc - * - */ -public class Decompiler { - - public static String decompile(byte[] bytecode) throws IOException { - String result = ""; - - File tempDirectory = new File(System.getProperty("java.io.tmpdir")); - File file = new File(tempDirectory, UUID.randomUUID().toString()); - FileUtils.writeByteArrayToFile(file, bytecode); - - result = decompile(file.getAbsolutePath(), null); - return result; - } - - public static String decompile(String path) throws IOException { - byte[] byteArray = FileUtils.readFileToByteArray(new File(path)); - return decompile(byteArray); - } - - public static String toString(MethodNode methodNode) { - Printer printer = new Textifier(); - TraceMethodVisitor methodPrinter = new TraceMethodVisitor(printer); - - methodNode.accept(methodPrinter); - - StringWriter sw = new StringWriter(); - printer.print(new PrintWriter(sw)); - printer.getText().clear(); - - return sw.toString(); - } - - public static String toString(ClassNode classNode) { - Printer printer = new Textifier(); - StringWriter sw = new StringWriter(); - PrintWriter printWriter = new PrintWriter(sw); - - TraceClassVisitor traceClassVisitor = new TraceClassVisitor(printWriter); - - classNode.accept(traceClassVisitor); - - printer.print(printWriter); - printer.getText().clear(); - - return sw.toString(); - } - - - - public static String toString(InsnList insnList) { - Printer printer = new Textifier(); - TraceMethodVisitor mp = new TraceMethodVisitor(printer); - insnList.accept(mp); - - StringWriter sw = new StringWriter(); - printer.print(new PrintWriter(sw)); - printer.getText().clear(); - return sw.toString(); - } - - public static String toString(AbstractInsnNode insn) { - Printer printer = new Textifier(); - TraceMethodVisitor mp = new TraceMethodVisitor(printer); - insn.accept(mp); - - StringWriter sw = new StringWriter(); - printer.print(new PrintWriter(sw)); - printer.getText().clear(); - return sw.toString(); - } - - - /** - * @param classFilePath - * @param methodName - * @return - */ - public static String decompile(String classFilePath, String methodName) { - final StringBuilder result = new StringBuilder(8192); - - OutputSinkFactory mySink = new OutputSinkFactory() { - @Override - public List getSupportedSinks(SinkType sinkType, Collection collection) { - return Arrays.asList(SinkClass.STRING, SinkClass.DECOMPILED, SinkClass.DECOMPILED_MULTIVER, - SinkClass.EXCEPTION_MESSAGE); - } - - @Override - public Sink getSink(final SinkType sinkType, SinkClass sinkClass) { - return new Sink() { - @Override - public void write(T sinkable) { - // skip message like: Analysing type demo.MathGame - if (sinkType == SinkType.PROGRESS) { - return; - } - result.append(sinkable); - } - }; - } - }; - - HashMap options = new HashMap(); - /** - * @see org.benf.cfr.reader.util.MiscConstants.Version.getVersion() Currently, - * the cfr version is wrong. so disable show cfr version. - */ - options.put("showversion", "false"); - if (methodName != null) { - options.put("methodname", methodName); - } - - CfrDriver driver = new CfrDriver.Builder().withOptions(options).withOutputSink(mySink).build(); - List toAnalyse = new ArrayList(); - toAnalyse.add(classFilePath); - driver.analyse(toAnalyse); - - return result.toString(); - } - - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/InstanceUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/InstanceUtils.java deleted file mode 100644 index a1526b8f9..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/InstanceUtils.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -public class InstanceUtils { - - public static T newInstance(Class clazz) { - try { - return clazz.newInstance(); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/MatchUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/MatchUtils.java deleted file mode 100644 index 077040521..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/MatchUtils.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.taobao.arthas.bytekit.utils; -import java.util.ArrayList; -import java.util.Stack; - -/** - * from org.apache.commons.io.FilenameUtils - * - * @author hengyunabc - * - */ -public class MatchUtils { - - /** - * The wildcard matcher uses the characters '?' and '*' to represent a - * single or multiple wildcard characters. - * - * @param str - * @param wildcardMatcher - * @return - */ - public static boolean wildcardMatch(String str, String wildcardMatcher) { - return wildcardMatch(str, wildcardMatcher, false); - } - - /** - * The wildcard matcher uses the characters '?' and '*' to represent a - * single or multiple wildcard characters. - * - * @param str - * @param wildcardMatcher - * @param sensitive - * if sensitive is true, str and wildcardMatcher will - * toLowerCase. - * @return - */ - public static boolean wildcardMatch(String str, String wildcardMatcher, boolean sensitive) { - if (str == null && wildcardMatcher == null) { - return true; - } - if (str == null || wildcardMatcher == null) { - return false; - } - str = convertCase(str, sensitive); - wildcardMatcher = convertCase(wildcardMatcher, sensitive); - String[] wcs = splitOnTokens(wildcardMatcher); - boolean anyChars = false; - int textIdx = 0; - int wcsIdx = 0; - Stack backtrack = new Stack(); - - // loop around a backtrack stack, to handle complex * matching - do { - if (backtrack.size() > 0) { - int[] array = (int[]) backtrack.pop(); - wcsIdx = array[0]; - textIdx = array[1]; - anyChars = true; - } - - // loop whilst tokens and text left to process - while (wcsIdx < wcs.length) { - - if (wcs[wcsIdx].equals("?")) { - // ? so move to next text char - textIdx++; - anyChars = false; - - } else if (wcs[wcsIdx].equals("*")) { - // set any chars status - anyChars = true; - if (wcsIdx == wcs.length - 1) { - textIdx = str.length(); - } - - } else { - // matching text token - if (anyChars) { - // any chars then try to locate text token - textIdx = str.indexOf(wcs[wcsIdx], textIdx); - if (textIdx == -1) { - // token not found - break; - } - int repeat = str.indexOf(wcs[wcsIdx], textIdx + 1); - if (repeat >= 0) { - backtrack.push(new int[] { wcsIdx, repeat }); - } - } else { - // matching from current position - if (!str.startsWith(wcs[wcsIdx], textIdx)) { - // couldnt match token - break; - } - } - - // matched text token, move text index to end of matched - // token - textIdx += wcs[wcsIdx].length(); - anyChars = false; - } - - wcsIdx++; - } - - // full match - if (wcsIdx == wcs.length && textIdx == str.length()) { - return true; - } - - } while (backtrack.size() > 0); - - return false; - } - - /** - * Splits a string into a number of tokens. - * - * @param text - * the text to split - * @return the tokens, never null - */ - static String[] splitOnTokens(String text) { - // used by wildcardMatch - // package level so a unit test may run on this - - if (text.indexOf("?") == -1 && text.indexOf("*") == -1) { - return new String[] { text }; - } - - char[] array = text.toCharArray(); - ArrayList list = new ArrayList(); - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < array.length; i++) { - if (array[i] == '?' || array[i] == '*') { - if (buffer.length() != 0) { - list.add(buffer.toString()); - buffer.setLength(0); - } - if (array[i] == '?') { - list.add("?"); - } else if (list.size() == 0 || (i > 0 && list.get(list.size() - 1).equals("*") == false)) { - list.add("*"); - } - } else { - buffer.append(array[i]); - } - } - if (buffer.length() != 0) { - list.add(buffer.toString()); - } - - return (String[]) list.toArray(new String[list.size()]); - } - - /** - * Converts the case of the input String to a standard format. Subsequent - * operations can then use standard String methods. - * - * @param str - * the string to convert, null returns null - * @return the lower-case version if case-insensitive - */ - static String convertCase(String str, boolean sensitive) { - if (str == null) { - return null; - } - return sensitive ? str : str.toLowerCase(); - } -} \ No newline at end of file diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/MethodUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/MethodUtils.java deleted file mode 100644 index 8023d3b24..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/MethodUtils.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -public class MethodUtils { - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/ReflectionUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/ReflectionUtils.java deleted file mode 100644 index b96f30b3c..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/ReflectionUtils.java +++ /dev/null @@ -1,807 +0,0 @@ -/* - * Copyright 2002-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.taobao.arthas.bytekit.utils; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.UndeclaredThrowableException; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Simple utility class for working with the reflection API and handling - * reflection exceptions. - * - *

Only intended for internal use. - * - * @author Juergen Hoeller - * @author Rob Harrop - * @author Rod Johnson - * @author Costin Leau - * @author Sam Brannen - * @author Chris Beams - * @since 1.2.2 - */ -public abstract class ReflectionUtils { - - /** - * Naming prefix for CGLIB-renamed methods. - * @see #isCglibRenamedMethod - */ - private static final String CGLIB_RENAMED_METHOD_PREFIX = "CGLIB$"; - - /** - * Attempt to find a {@link Field field} on the supplied {@link Class} with the - * supplied {@code name}. Searches all superclasses up to {@link Object}. - * @param clazz the class to introspect - * @param name the name of the field - * @return the corresponding Field object, or {@code null} if not found - */ - public static Field findField(Class clazz, String name) { - return findField(clazz, name, null); - } - - /** - * Attempt to find a {@link Field field} on the supplied {@link Class} with the - * supplied {@code name} and/or {@link Class type}. Searches all superclasses - * up to {@link Object}. - * @param clazz the class to introspect - * @param name the name of the field (may be {@code null} if type is specified) - * @param type the type of the field (may be {@code null} if name is specified) - * @return the corresponding Field object, or {@code null} if not found - */ - public static Field findField(Class clazz, String name, Class type) { - Class searchType = clazz; - while (Object.class != searchType && searchType != null) { - Field[] fields = getDeclaredFields(searchType); - for (Field field : fields) { - if ((name == null || name.equals(field.getName())) && - (type == null || type.equals(field.getType()))) { - return field; - } - } - searchType = searchType.getSuperclass(); - } - return null; - } - - /** - * Set the field represented by the supplied {@link Field field object} on the - * specified {@link Object target object} to the specified {@code value}. - * In accordance with {@link Field#set(Object, Object)} semantics, the new value - * is automatically unwrapped if the underlying field has a primitive type. - *

Thrown exceptions are handled via a call to {@link #handleReflectionException(Exception)}. - * @param field the field to set - * @param target the target object on which to set the field - * @param value the value to set (may be {@code null}) - */ - public static void setField(Field field, Object target, Object value) { - try { - field.set(target, value); - } - catch (IllegalAccessException ex) { - handleReflectionException(ex); - throw new IllegalStateException( - "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); - } - } - - /** - * Get the field represented by the supplied {@link Field field object} on the - * specified {@link Object target object}. In accordance with {@link Field#get(Object)} - * semantics, the returned value is automatically wrapped if the underlying field - * has a primitive type. - *

Thrown exceptions are handled via a call to {@link #handleReflectionException(Exception)}. - * @param field the field to get - * @param target the target object from which to get the field - * @return the field's current value - */ - public static Object getField(Field field, Object target) { - try { - return field.get(target); - } - catch (IllegalAccessException ex) { - handleReflectionException(ex); - throw new IllegalStateException( - "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); - } - } - - /** - * Attempt to find a {@link Method} on the supplied class with the supplied name - * and no parameters. Searches all superclasses up to {@code Object}. - *

Returns {@code null} if no {@link Method} can be found. - * @param clazz the class to introspect - * @param name the name of the method - * @return the Method object, or {@code null} if none found - */ - public static Method findMethod(Class clazz, String name) { - return findMethod(clazz, name, new Class[0]); - } - - /** - * Attempt to find a {@link Method} on the supplied class with the supplied name - * and parameter types. Searches all superclasses up to {@code Object}. - *

Returns {@code null} if no {@link Method} can be found. - * @param clazz the class to introspect - * @param name the name of the method - * @param paramTypes the parameter types of the method - * (may be {@code null} to indicate any signature) - * @return the Method object, or {@code null} if none found - */ - public static Method findMethod(Class clazz, String name, Class... paramTypes) { - Class searchType = clazz; - while (searchType != null) { - Method[] methods = (searchType.isInterface() ? searchType.getMethods() : getDeclaredMethods(searchType)); - for (Method method : methods) { - if (name.equals(method.getName()) && - (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) { - return method; - } - } - searchType = searchType.getSuperclass(); - } - return null; - } - - /** - * Invoke the specified {@link Method} against the supplied target object with no arguments. - * The target object can be {@code null} when invoking a static {@link Method}. - *

Thrown exceptions are handled via a call to {@link #handleReflectionException}. - * @param method the method to invoke - * @param target the target object to invoke the method on - * @return the invocation result, if any - * @see #invokeMethod(java.lang.reflect.Method, Object, Object[]) - */ - public static Object invokeMethod(Method method, Object target) { - return invokeMethod(method, target, new Object[0]); - } - - /** - * Invoke the specified {@link Method} against the supplied target object with the - * supplied arguments. The target object can be {@code null} when invoking a - * static {@link Method}. - *

Thrown exceptions are handled via a call to {@link #handleReflectionException}. - * @param method the method to invoke - * @param target the target object to invoke the method on - * @param args the invocation arguments (may be {@code null}) - * @return the invocation result, if any - */ - public static Object invokeMethod(Method method, Object target, Object... args) { - try { - return method.invoke(target, args); - } - catch (Exception ex) { - handleReflectionException(ex); - } - throw new IllegalStateException("Should never get here"); - } - - /** - * Invoke the specified JDBC API {@link Method} against the supplied target - * object with no arguments. - * @param method the method to invoke - * @param target the target object to invoke the method on - * @return the invocation result, if any - * @throws SQLException the JDBC API SQLException to rethrow (if any) - * @see #invokeJdbcMethod(java.lang.reflect.Method, Object, Object[]) - */ - public static Object invokeJdbcMethod(Method method, Object target) throws SQLException { - return invokeJdbcMethod(method, target, new Object[0]); - } - - /** - * Invoke the specified JDBC API {@link Method} against the supplied target - * object with the supplied arguments. - * @param method the method to invoke - * @param target the target object to invoke the method on - * @param args the invocation arguments (may be {@code null}) - * @return the invocation result, if any - * @throws SQLException the JDBC API SQLException to rethrow (if any) - * @see #invokeMethod(java.lang.reflect.Method, Object, Object[]) - */ - public static Object invokeJdbcMethod(Method method, Object target, Object... args) throws SQLException { - try { - return method.invoke(target, args); - } - catch (IllegalAccessException ex) { - handleReflectionException(ex); - } - catch (InvocationTargetException ex) { - if (ex.getTargetException() instanceof SQLException) { - throw (SQLException) ex.getTargetException(); - } - handleInvocationTargetException(ex); - } - throw new IllegalStateException("Should never get here"); - } - - /** - * Handle the given reflection exception. Should only be called if no - * checked exception is expected to be thrown by the target method. - *

Throws the underlying RuntimeException or Error in case of an - * InvocationTargetException with such a root cause. Throws an - * IllegalStateException with an appropriate message or - * UndeclaredThrowableException otherwise. - * @param ex the reflection exception to handle - */ - public static void handleReflectionException(Exception ex) { - if (ex instanceof NoSuchMethodException) { - throw new IllegalStateException("Method not found: " + ex.getMessage()); - } - if (ex instanceof IllegalAccessException) { - throw new IllegalStateException("Could not access method: " + ex.getMessage()); - } - if (ex instanceof InvocationTargetException) { - handleInvocationTargetException((InvocationTargetException) ex); - } - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } - throw new UndeclaredThrowableException(ex); - } - - /** - * Handle the given invocation target exception. Should only be called if no - * checked exception is expected to be thrown by the target method. - *

Throws the underlying RuntimeException or Error in case of such a root - * cause. Throws an UndeclaredThrowableException otherwise. - * @param ex the invocation target exception to handle - */ - public static void handleInvocationTargetException(InvocationTargetException ex) { - rethrowRuntimeException(ex.getTargetException()); - } - - /** - * Rethrow the given {@link Throwable exception}, which is presumably the - * target exception of an {@link InvocationTargetException}. - * Should only be called if no checked exception is expected to be thrown - * by the target method. - *

Rethrows the underlying exception cast to a {@link RuntimeException} or - * {@link Error} if appropriate; otherwise, throws an - * {@link UndeclaredThrowableException}. - * @param ex the exception to rethrow - * @throws RuntimeException the rethrown exception - */ - public static void rethrowRuntimeException(Throwable ex) { - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } - if (ex instanceof Error) { - throw (Error) ex; - } - throw new UndeclaredThrowableException(ex); - } - - /** - * Rethrow the given {@link Throwable exception}, which is presumably the - * target exception of an {@link InvocationTargetException}. - * Should only be called if no checked exception is expected to be thrown - * by the target method. - *

Rethrows the underlying exception cast to an {@link Exception} or - * {@link Error} if appropriate; otherwise, throws an - * {@link UndeclaredThrowableException}. - * @param ex the exception to rethrow - * @throws Exception the rethrown exception (in case of a checked exception) - */ - public static void rethrowException(Throwable ex) throws Exception { - if (ex instanceof Exception) { - throw (Exception) ex; - } - if (ex instanceof Error) { - throw (Error) ex; - } - throw new UndeclaredThrowableException(ex); - } - - /** - * Determine whether the given method explicitly declares the given - * exception or one of its superclasses, which means that an exception - * of that type can be propagated as-is within a reflective invocation. - * @param method the declaring method - * @param exceptionType the exception to throw - * @return {@code true} if the exception can be thrown as-is; - * {@code false} if it needs to be wrapped - */ - public static boolean declaresException(Method method, Class exceptionType) { - Class[] declaredExceptions = method.getExceptionTypes(); - for (Class declaredException : declaredExceptions) { - if (declaredException.isAssignableFrom(exceptionType)) { - return true; - } - } - return false; - } - - /** - * Determine whether the given field is a "public static final" constant. - * @param field the field to check - */ - public static boolean isPublicStaticFinal(Field field) { - int modifiers = field.getModifiers(); - return (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)); - } - - /** - * Determine whether the given method is an "equals" method. - * @see java.lang.Object#equals(Object) - */ - public static boolean isEqualsMethod(Method method) { - if (method == null || !method.getName().equals("equals")) { - return false; - } - Class[] paramTypes = method.getParameterTypes(); - return (paramTypes.length == 1 && paramTypes[0] == Object.class); - } - - /** - * Determine whether the given method is a "hashCode" method. - * @see java.lang.Object#hashCode() - */ - public static boolean isHashCodeMethod(Method method) { - return (method != null && method.getName().equals("hashCode") && method.getParameterTypes().length == 0); - } - - /** - * Determine whether the given method is a "toString" method. - * @see java.lang.Object#toString() - */ - public static boolean isToStringMethod(Method method) { - return (method != null && method.getName().equals("toString") && method.getParameterTypes().length == 0); - } - - /** - * Determine whether the given method is originally declared by {@link java.lang.Object}. - */ - public static boolean isObjectMethod(Method method) { - if (method == null) { - return false; - } - try { - Object.class.getDeclaredMethod(method.getName(), method.getParameterTypes()); - return true; - } - catch (Exception ex) { - return false; - } - } - - /** - * Determine whether the given method is a CGLIB 'renamed' method, - * following the pattern "CGLIB$methodName$0". - * @param renamedMethod the method to check - * @see org.springframework.cglib.proxy.Enhancer#rename - */ - public static boolean isCglibRenamedMethod(Method renamedMethod) { - String name = renamedMethod.getName(); - if (name.startsWith(CGLIB_RENAMED_METHOD_PREFIX)) { - int i = name.length() - 1; - while (i >= 0 && Character.isDigit(name.charAt(i))) { - i--; - } - return ((i > CGLIB_RENAMED_METHOD_PREFIX.length()) && - (i < name.length() - 1) && name.charAt(i) == '$'); - } - return false; - } - - /** - * Make the given field accessible, explicitly setting it accessible if - * necessary. The {@code setAccessible(true)} method is only called - * when actually necessary, to avoid unnecessary conflicts with a JVM - * SecurityManager (if active). - * @param field the field to make accessible - * @see java.lang.reflect.Field#setAccessible - */ - public static void makeAccessible(Field field) { - if ((!Modifier.isPublic(field.getModifiers()) || - !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || - Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { - field.setAccessible(true); - } - } - - /** - * Make the given method accessible, explicitly setting it accessible if - * necessary. The {@code setAccessible(true)} method is only called - * when actually necessary, to avoid unnecessary conflicts with a JVM - * SecurityManager (if active). - * @param method the method to make accessible - * @see java.lang.reflect.Method#setAccessible - */ - public static void makeAccessible(Method method) { - if ((!Modifier.isPublic(method.getModifiers()) || - !Modifier.isPublic(method.getDeclaringClass().getModifiers())) && !method.isAccessible()) { - method.setAccessible(true); - } - } - - /** - * Make the given constructor accessible, explicitly setting it accessible - * if necessary. The {@code setAccessible(true)} method is only called - * when actually necessary, to avoid unnecessary conflicts with a JVM - * SecurityManager (if active). - * @param ctor the constructor to make accessible - * @see java.lang.reflect.Constructor#setAccessible - */ - public static void makeAccessible(Constructor ctor) { - if ((!Modifier.isPublic(ctor.getModifiers()) || - !Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) { - ctor.setAccessible(true); - } - } - - /** - * Perform the given callback operation on all matching methods of the given - * class, as locally declared or equivalent thereof (such as default methods - * on Java 8 based interfaces that the given class implements). - * @param clazz the class to introspect - * @param mc the callback to invoke for each method - * @since 4.2 - * @see #doWithMethods - */ - public static void doWithLocalMethods(Class clazz, MethodCallback mc) { - Method[] methods = getDeclaredMethods(clazz); - for (Method method : methods) { - try { - mc.doWith(method); - } - catch (IllegalAccessException ex) { - throw new IllegalStateException("Not allowed to access method '" + method.getName() + "': " + ex); - } - } - } - - /** - * Perform the given callback operation on all matching methods of the given - * class and superclasses. - *

The same named method occurring on subclass and superclass will appear - * twice, unless excluded by a {@link MethodFilter}. - * @param clazz the class to introspect - * @param mc the callback to invoke for each method - * @see #doWithMethods(Class, MethodCallback, MethodFilter) - */ - public static void doWithMethods(Class clazz, MethodCallback mc) { - doWithMethods(clazz, mc, null); - } - - /** - * Perform the given callback operation on all matching methods of the given - * class and superclasses (or given interface and super-interfaces). - *

The same named method occurring on subclass and superclass will appear - * twice, unless excluded by the specified {@link MethodFilter}. - * @param clazz the class to introspect - * @param mc the callback to invoke for each method - * @param mf the filter that determines the methods to apply the callback to - */ - public static void doWithMethods(Class clazz, MethodCallback mc, MethodFilter mf) { - // Keep backing up the inheritance hierarchy. - Method[] methods = getDeclaredMethods(clazz); - for (Method method : methods) { - if (mf != null && !mf.matches(method)) { - continue; - } - try { - mc.doWith(method); - } - catch (IllegalAccessException ex) { - throw new IllegalStateException("Not allowed to access method '" + method.getName() + "': " + ex); - } - } - if (clazz.getSuperclass() != null) { - doWithMethods(clazz.getSuperclass(), mc, mf); - } - else if (clazz.isInterface()) { - for (Class superIfc : clazz.getInterfaces()) { - doWithMethods(superIfc, mc, mf); - } - } - } - - /** - * Get all declared methods on the leaf class and all superclasses. - * Leaf class methods are included first. - * @param leafClass the class to introspect - */ - public static Method[] getAllDeclaredMethods(Class leafClass) { - final List methods = new ArrayList(32); - doWithMethods(leafClass, new MethodCallback() { - @Override - public void doWith(Method method) { - methods.add(method); - } - }); - return methods.toArray(new Method[methods.size()]); - } - - /** - * Get the unique set of declared methods on the leaf class and all superclasses. - * Leaf class methods are included first and while traversing the superclass hierarchy - * any methods found with signatures matching a method already included are filtered out. - * @param leafClass the class to introspect - */ - public static Method[] getUniqueDeclaredMethods(Class leafClass) { - final List methods = new ArrayList(32); - doWithMethods(leafClass, new MethodCallback() { - @Override - public void doWith(Method method) { - boolean knownSignature = false; - Method methodBeingOverriddenWithCovariantReturnType = null; - for (Method existingMethod : methods) { - if (method.getName().equals(existingMethod.getName()) && - Arrays.equals(method.getParameterTypes(), existingMethod.getParameterTypes())) { - // Is this a covariant return type situation? - if (existingMethod.getReturnType() != method.getReturnType() && - existingMethod.getReturnType().isAssignableFrom(method.getReturnType())) { - methodBeingOverriddenWithCovariantReturnType = existingMethod; - } - else { - knownSignature = true; - } - break; - } - } - if (methodBeingOverriddenWithCovariantReturnType != null) { - methods.remove(methodBeingOverriddenWithCovariantReturnType); - } - if (!knownSignature && !isCglibRenamedMethod(method)) { - methods.add(method); - } - } - }); - return methods.toArray(new Method[methods.size()]); - } - - /** - * This variant retrieves {@link Class#getDeclaredMethods()} from a local cache - * in order to avoid the JVM's SecurityManager check and defensive array copying. - * In addition, it also includes Java 8 default methods from locally implemented - * interfaces, since those are effectively to be treated just like declared methods. - * @param clazz the class to introspect - * @return the cached array of methods - * @see Class#getDeclaredMethods() - */ - private static Method[] getDeclaredMethods(Class clazz) { - Method[] result = null; - if (result == null) { - Method[] declaredMethods = clazz.getDeclaredMethods(); - List defaultMethods = findConcreteMethodsOnInterfaces(clazz); - if (defaultMethods != null) { - result = new Method[declaredMethods.length + defaultMethods.size()]; - System.arraycopy(declaredMethods, 0, result, 0, declaredMethods.length); - int index = declaredMethods.length; - for (Method defaultMethod : defaultMethods) { - result[index] = defaultMethod; - index++; - } - } - else { - result = declaredMethods; - } - } - return result; - } - - private static List findConcreteMethodsOnInterfaces(Class clazz) { - List result = null; - for (Class ifc : clazz.getInterfaces()) { - for (Method ifcMethod : ifc.getMethods()) { - if (!Modifier.isAbstract(ifcMethod.getModifiers())) { - if (result == null) { - result = new LinkedList(); - } - result.add(ifcMethod); - } - } - } - return result; - } - - /** - * Invoke the given callback on all fields in the target class, going up the - * class hierarchy to get all declared fields. - * @param clazz the target class to analyze - * @param fc the callback to invoke for each field - * @since 4.2 - * @see #doWithFields - */ - public static void doWithLocalFields(Class clazz, FieldCallback fc) { - for (Field field : getDeclaredFields(clazz)) { - try { - fc.doWith(field); - } - catch (IllegalAccessException ex) { - throw new IllegalStateException("Not allowed to access field '" + field.getName() + "': " + ex); - } - } - } - - /** - * Invoke the given callback on all fields in the target class, going up the - * class hierarchy to get all declared fields. - * @param clazz the target class to analyze - * @param fc the callback to invoke for each field - */ - public static void doWithFields(Class clazz, FieldCallback fc) { - doWithFields(clazz, fc, null); - } - - /** - * Invoke the given callback on all fields in the target class, going up the - * class hierarchy to get all declared fields. - * @param clazz the target class to analyze - * @param fc the callback to invoke for each field - * @param ff the filter that determines the fields to apply the callback to - */ - public static void doWithFields(Class clazz, FieldCallback fc, FieldFilter ff) { - // Keep backing up the inheritance hierarchy. - Class targetClass = clazz; - do { - Field[] fields = getDeclaredFields(targetClass); - for (Field field : fields) { - if (ff != null && !ff.matches(field)) { - continue; - } - try { - fc.doWith(field); - } - catch (IllegalAccessException ex) { - throw new IllegalStateException("Not allowed to access field '" + field.getName() + "': " + ex); - } - } - targetClass = targetClass.getSuperclass(); - } - while (targetClass != null && targetClass != Object.class); - } - - /** - * This variant retrieves {@link Class#getDeclaredFields()} from a local cache - * in order to avoid the JVM's SecurityManager check and defensive array copying. - * @param clazz the class to introspect - * @return the cached array of fields - * @see Class#getDeclaredFields() - */ - private static Field[] getDeclaredFields(Class clazz) { - Field[] result = null; - if (result == null) { - result = clazz.getDeclaredFields(); - } - return result; - } - - /** - * Given the source object and the destination, which must be the same class - * or a subclass, copy all fields, including inherited fields. Designed to - * work on objects with public no-arg constructors. - */ - public static void shallowCopyFieldState(final Object src, final Object dest) { - if (src == null) { - throw new IllegalArgumentException("Source for field copy cannot be null"); - } - if (dest == null) { - throw new IllegalArgumentException("Destination for field copy cannot be null"); - } - if (!src.getClass().isAssignableFrom(dest.getClass())) { - throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() + - "] must be same or subclass as source class [" + src.getClass().getName() + "]"); - } - doWithFields(src.getClass(), new FieldCallback() { - @Override - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { - makeAccessible(field); - Object srcValue = field.get(src); - field.set(dest, srcValue); - } - }, COPYABLE_FIELDS); - } - - - /** - * Action to take on each method. - */ - public interface MethodCallback { - - /** - * Perform an operation using the given method. - * @param method the method to operate on - */ - void doWith(Method method) throws IllegalArgumentException, IllegalAccessException; - } - - - /** - * Callback optionally used to filter methods to be operated on by a method callback. - */ - public interface MethodFilter { - - /** - * Determine whether the given method matches. - * @param method the method to check - */ - boolean matches(Method method); - } - - - /** - * Callback interface invoked on each field in the hierarchy. - */ - public interface FieldCallback { - - /** - * Perform an operation using the given field. - * @param field the field to operate on - */ - void doWith(Field field) throws IllegalArgumentException, IllegalAccessException; - } - - - /** - * Callback optionally used to filter fields to be operated on by a field callback. - */ - public interface FieldFilter { - - /** - * Determine whether the given field matches. - * @param field the field to check - */ - boolean matches(Field field); - } - - - /** - * Pre-built FieldFilter that matches all non-static, non-final fields. - */ - public static final FieldFilter COPYABLE_FIELDS = new FieldFilter() { - - @Override - public boolean matches(Field field) { - return !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())); - } - }; - - - /** - * Pre-built MethodFilter that matches all non-bridge methods. - */ - public static final MethodFilter NON_BRIDGED_METHODS = new MethodFilter() { - - @Override - public boolean matches(Method method) { - return !method.isBridge(); - } - }; - - - /** - * Pre-built MethodFilter that matches all non-bridge methods - * which are not declared on {@code java.lang.Object}. - */ - public static final MethodFilter USER_DECLARED_METHODS = new MethodFilter() { - - @Override - public boolean matches(Method method) { - return (!method.isBridge() && method.getDeclaringClass() != Object.class); - } - }; - -} diff --git a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/VerifyUtils.java b/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/VerifyUtils.java deleted file mode 100644 index 98eed71aa..000000000 --- a/bytekit/src/main/java/com/taobao/arthas/bytekit/utils/VerifyUtils.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; - -import com.alibaba.arthas.deps.org.objectweb.asm.ClassReader; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassWriter; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.util.CheckClassAdapter; - -/** - * - * @author hengyunabc - * - */ -public class VerifyUtils { - - public static void asmVerify(byte[] bytes, boolean printResults) throws IOException { - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - ClassReader cr = new ClassReader(inputStream); - CheckClassAdapter.verify(cr, true, new PrintWriter(System.out)); - } - - public static void asmVerify(byte[] bytes) throws IOException { - ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); - ClassReader cr = new ClassReader(inputStream); - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); - ClassVisitor cv = new CheckClassAdapter(cw); - - cr.accept(cv, 0); - } - - public static Object instanceVerity(byte[] bytes) throws Exception { - String name = Type.getObjectType(AsmUtils.toClassNode(bytes).name).getClassName(); - - @SuppressWarnings("resource") - ClassbyteClassLoader cl = new ClassbyteClassLoader(ClassLoaderUtils.getUrls(ClassLoader.getSystemClassLoader()), - ClassLoader.getSystemClassLoader().getParent()); - - cl.addClass(name, bytes); - - Class loadClass = cl.loadClass(name); - return loadClass.newInstance(); - } - - public static Object invoke(Object instance, String name, Object... args) throws Exception { - Method[] methods = instance.getClass().getMethods(); - for (Method method : methods) { - if (name.contentEquals(method.getName())) { - return method.invoke(instance, args); - } - } - throw new NoSuchMethodError("name: " + name); - } - - public static class ClassbyteClassLoader extends URLClassLoader { - public ClassbyteClassLoader(URL[] urls, ClassLoader cl) { - super(urls, cl); - } - - public Class addClass(String name, byte[] bytes) throws ClassFormatError { - Class cl = defineClass(name, bytes, 0, bytes.length); - resolveClass(cl); - - return cl; - } - } - -} diff --git a/bytekit/src/test/java/com/example/ByteKitDemo.java b/bytekit/src/test/java/com/example/ByteKitDemo.java deleted file mode 100644 index bd6139f00..000000000 --- a/bytekit/src/test/java/com/example/ByteKitDemo.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.example; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.utils.AgentUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; - -/** - * - * @author hengyunabc 2020-05-21 - * - */ -public class ByteKitDemo { - - public static class Sample { - private int exceptionCount = 0; - - public String hello(String str, boolean exception) { - if (exception) { - exceptionCount++; - throw new RuntimeException("test exception, str: " + str); - } - return "hello " + str; - } - } - - public static class PrintExceptionSuppressHandler { - - @ExceptionHandler(inline = true) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.out.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class SampleInterceptor { - - @AtEnter(inline = true, suppress = RuntimeException.class, suppressHandler = PrintExceptionSuppressHandler.class) - public static void atEnter(@Binding.This Object object, - @Binding.Class Object clazz, - @Binding.Args Object[] args, - @Binding.MethodName String methodName, - @Binding.MethodDesc String methodDesc) { - System.out.println("atEnter, args[0]: " + args[0]); - } - - @AtExit(inline = true) - public static void atExit(@Binding.Return Object returnObject) { - System.out.println("atExit, returnObject: " + returnObject); - } - - @AtExceptionExit(inline = true, onException = RuntimeException.class) - public static void atExceptionExit(@Binding.Throwable RuntimeException ex, - @Binding.Field(name = "exceptionCount") int exceptionCount) { - System.out.println("atExceptionExit, ex: " + ex.getMessage() + ", field exceptionCount: " + exceptionCount); - } - } - - public static void main(String[] args) throws Exception { - AgentUtils.install(); - - // 启动Sample,不断执行 - final Sample sample = new Sample(); - Thread t = new Thread(new Runnable() { - @Override - public void run() { - for (int i = 0; i < 100; ++i) { - try { - TimeUnit.SECONDS.sleep(3); - String result = sample.hello("" + i, (i % 3) == 0); - System.out.println("call hello result: " + result); - } catch (Throwable e) { - // ignore - System.out.println("call hello exception: " + e.getMessage()); - } - } - } - }); - t.start(); - - // 解析定义的 Interceptor类 和相关的注解 - DefaultInterceptorClassParser interceptorClassParser = new DefaultInterceptorClassParser(); - List processors = interceptorClassParser.parse(SampleInterceptor.class); - - // 加载字节码 - ClassNode classNode = AsmUtils.loadClass(Sample.class); - - // 对加载到的字节码做增强处理 - for (MethodNode methodNode : classNode.methods) { - if (methodNode.name.equals("hello")) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode); - for (InterceptorProcessor interceptor : processors) { - interceptor.process(methodProcessor); - } - } - } - - // 获取增强后的字节码 - byte[] bytes = AsmUtils.toBytes(classNode); - - // 查看反编译结果 - System.out.println(Decompiler.decompile(bytes)); - - // 等待,查看未增强里的输出结果 - TimeUnit.SECONDS.sleep(10); - - // 通过 reTransform 增强类 - AgentUtils.reTransform(Sample.class, bytes); - System.in.read(); - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/TryCatchBlockTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/TryCatchBlockTest.java deleted file mode 100644 index ec34f6353..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/TryCatchBlockTest.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.taobao.arthas.bytekit.asm; - -import java.lang.instrument.Instrumentation; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.InsnList; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.JumpInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.LabelNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -import net.bytebuddy.agent.ByteBuddyAgent; - -public class TryCatchBlockTest { - - static public class Hello { - - public long sss(String msg, int i, long l) { - return 124L; - } - - public long toBeCall(int i , long l, String s) { - return l + i; - } - -// public String say(String msg, int i, long l) { -// i = 0; -// System.out.println("hello"); -// i = 0; -// sss(msg, i, l); -// return ""; -// } - - public int say(int ii) { - toBeCall(ii, 123L, ""); - return 123; - } - } - - public static void ttt() throws Throwable { - try { - System.out.println(); - } catch (Throwable e) { - e.printStackTrace(); - throw e; - } - try { - System.out.println(); - } catch (Throwable e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void test() throws Exception { - - Instrumentation instrumentation = ByteBuddyAgent.install(); - - ClassNode classNode = AsmUtils.loadClass(Hello.class); - - List methods = AsmUtils.findMethods(classNode.methods, "say"); - - MethodNode methodNode = methods.get(0); - - AbstractInsnNode insnNode = methodNode.instructions.getFirst(); - - List methodInsnNodes = new ArrayList(); - - while (insnNode != null) { - if (insnNode instanceof MethodInsnNode) { - MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode; - methodInsnNodes.add(methodInsnNode); - } - insnNode = insnNode.getNext(); - } - - for (MethodInsnNode methodInsnNode : methodInsnNodes) { - TryCatchBlock tryCatchBlock = new TryCatchBlock(methodNode); - - InsnList toInsert = new InsnList(); - - LabelNode gotoDest = new LabelNode(); - - LabelNode startLabelNode = tryCatchBlock.getStartLabelNode(); - LabelNode endLabelNode = tryCatchBlock.getEndLabelNode(); - - toInsert.add(new JumpInsnNode(Opcodes.GOTO, gotoDest)); - toInsert.add(endLabelNode); - - AsmOpUtils.dup(toInsert); - toInsert.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getType(Throwable.class).getInternalName(), - "printStackTrace", "()V", false)); - - AsmOpUtils.throwException(toInsert); - - toInsert.add(gotoDest); - - methodNode.instructions.insertBefore(methodInsnNode, startLabelNode); - methodNode.instructions.insert(methodInsnNode, toInsert); - - tryCatchBlock.sort(); - } - - byte[] bytes = AsmUtils.toBytes(classNode); - - String decompile = Decompiler.decompile(bytes); - System.err.println(decompile); - - VerifyUtils.asmVerify(bytes, true); - - VerifyUtils.instanceVerity(bytes); - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemo.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemo.java deleted file mode 100644 index 2daf425f5..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemo.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -public class InstDemo { - - public int returnInt(int i) { - System.out.println(new Object[] { i }); - return 9998; - } - - public static void onEnter(Object[] args) { - System.out.println(args); - } - - public static int returnIntStatic(int i) { - return 9998; - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemoTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemoTest.java deleted file mode 100644 index 8dc26a9f1..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemoTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -import java.util.List; - -import org.junit.Test; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AnnotationNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.FieldNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -public class InstDemoTest { - - @Test - public void test() throws Exception { - - ClassNode apmClassNode = AsmUtils.loadClass(InstDemo_APM.class); - - ClassNode originClassNode = AsmUtils.loadClass(InstDemo.class); - - ClassNode targetClassNode = AsmUtils.copy(originClassNode); - - - byte[] renameClass = AsmUtils.renameClass(AsmUtils.toBytes(apmClassNode), Type.getObjectType(originClassNode.name).getClassName()); - - apmClassNode = AsmUtils.toClassNode(renameClass); - - for(FieldNode fieldNode : apmClassNode.fields) { - if( fieldNode.visibleAnnotations != null) { - for( AnnotationNode annotationNode : fieldNode.visibleAnnotations) { - System.err.println(annotationNode.desc); - System.err.println(annotationNode.values); - - if(Type.getType(NewField.class).equals(Type.getType(annotationNode.desc))) { - AsmUtils.addField(targetClassNode, fieldNode); - } - - } - } - } - - for (MethodNode methodNode : apmClassNode.methods) { - methodNode = AsmUtils.removeLineNumbers(methodNode); - if (methodNode.name.startsWith("__origin_")) { - continue; - } else { - MethodNode findMethod = AsmUtils.findMethod(originClassNode.methods, methodNode); - if (findMethod != null) { - // 先要替换 invokeOrigin ,要判断 - // 从 apm 里查找 __origin_ 开头的函数,忽略 - // 查找 非 __origin_ 开头的函数,在原来的类里查找,如果有同样签名的函数 - // 则从函数里查找 是否有 __origin_ 的函数调用。如果有的话,则从原有的类里查找到 method,再inline掉。 - - List originMethodInsnNodes = AsmUtils.findMethodInsnNodeWithPrefix(methodNode, - "__origin_"); - - for (MethodInsnNode methodInsnNode : originMethodInsnNodes) { - String toInlineMethodName = methodInsnNode.name.substring("__origin_".length()); - MethodNode originMethodNode = AsmUtils.findMethod(originClassNode.methods, toInlineMethodName, - findMethod.desc); - - MethodNode tmpMethodNode = AsmUtils.copy(originMethodNode); - tmpMethodNode.name = methodInsnNode.name; - - MethodProcessor methodProcessor = new MethodProcessor(apmClassNode.name, methodNode); - methodProcessor.inline(originClassNode.name, tmpMethodNode); - - AsmUtils.replaceMethod(targetClassNode, methodProcessor.getMethodNode()); - - } - - } else { - // 没找到的函数,则加进去 - AsmUtils.addMethod(targetClassNode, methodNode); - } - } - - - } - - byte[] resutlBytes = AsmUtils.toBytes(targetClassNode); - - System.err.println(Decompiler.decompile(resutlBytes)); - - System.err.println(AsmUtils.toASMCode(resutlBytes)); - - VerifyUtils.asmVerify(resutlBytes); - VerifyUtils.instanceVerity(resutlBytes); - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemo_APM.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemo_APM.java deleted file mode 100644 index 75cfd3aed..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InstDemo_APM.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -@Instrument -public class InstDemo_APM { - - @NewField - private String newField; - - public int newMethod(String s) { - return s.length() + 998; - } - - // 这种方式来写怎么样?有点丑,但是不需要写那些转换的代码。 在插件的编绎出结果后,可以检查下 名字,static,参数等是否匹配的。 - // 这种处理有点丑,但inline应该没问题 - public int __origin_returnInt(int i) { - return 0; - } - - public int returnInt(int i) { - - int re = __origin_returnInt(i); - - return 9998 + re; - } - - public static int returnIntStatic(int i) { - return 9998; - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginDemo.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginDemo.java deleted file mode 100644 index 041d26ea0..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginDemo.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -import java.util.Date; - -/** - * @author hengyunabc 2019-03-13 - * - */ -public class InvokeOriginDemo { - - public void returnVoid() { - } - - public Void returnVoidObject() { - int i = 0; - try { - int parseInt = Integer.parseInt("1000"); - i += parseInt; - } catch (Exception e) { - System.err.println(i + " " + e); - } - - return null; - } - - public int returnInt(int i) { - return 9998; - } - - public int returnIntToObject(int i) { - - return 9998; - } - - public int returnIntToInteger(int i) { - - return 9998; - } - - public static int returnIntStatic(int i) { - return 9998; - } - - public long returnLong() { - return 9998L; - } - - public long returnLongToObject() { - return 9998L; - } - - public String[] returnStrArray() { - String[] result = new String[] {"abc", "xyz" , "ufo"}; - return result; - } - - public String[] returnStrArrayWithArgs(int i, String s, long l) { - String[] result = new String[] {"abc" + i, "xyz" + s , "ufo" + l}; - return result; - } - - public String returnStr() { - return new Date().toString(); - } - - public Object returnObject() { - return InvokeOriginDemo.class; - } - - - public int recursive(int i) { - if (i == 1) { - return 1; - } - return i + recursive(i - 1); - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginDemo_APM.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginDemo_APM.java deleted file mode 100644 index a5d41a27d..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginDemo_APM.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -/** - * - * @author hengyunabc 2019-03-18 - * - */ -public class InvokeOriginDemo_APM { - - public void returnVoid() { - Object o = InstrumentApi.invokeOrigin(); - System.out.println(o); - } - - public Void returnVoidObject() { - Void v = InstrumentApi.invokeOrigin(); - System.out.println(v); - return v; - } - - public int returnInt(int i) { - System.out.println("before"); - int value = InstrumentApi.invokeOrigin(); - System.out.println("after"); - return value + 123; - } - - public int returnIntToObject(int i) { - Object value = InstrumentApi.invokeOrigin(); - return 9998 + (Integer) value; - } - - public int returnIntToInteger(int i) { - - Integer ixx = InstrumentApi.invokeOrigin(); - - return ixx + 9998; - } - - public static int returnIntStatic(int i) { - int result = InstrumentApi.invokeOrigin(); - return 9998 + result; - } - - public long returnLong() { - long result = InstrumentApi.invokeOrigin(); - return 9998L + result; - } - - public long returnLongToObject() { - Long lll = InstrumentApi.invokeOrigin(); - return 9998L + lll; - } - - public String[] returnStrArray() { - String[] result = InstrumentApi.invokeOrigin(); - System.err.println(result); - return result; - } - - public String[] returnStrArrayWithArgs(int i, String s, long l) { - System.out.println(i); - String[] result = InstrumentApi.invokeOrigin(); - result[0] = "fff"; - return result; - } - - public String returnStr() { - System.err.println("ssss"); - Object result = InstrumentApi.invokeOrigin(); - return "hello" + result; - } - - public Object returnObject() { - InstrumentApi.invokeOrigin(); - return InvokeOriginDemo.class; - } - - public int recursive(int i) { - int result = InstrumentApi.invokeOrigin(); - - System.err.println(result); - return result; - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginTest.java deleted file mode 100644 index 4410b1a31..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/inst/InvokeOriginTest.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.taobao.arthas.bytekit.asm.inst; - -import java.io.IOException; - -import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -import com.taobao.arthas.bytekit.asm.inst.impl.InstrumentImpl; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -/** - * - * @author hengyunabc 2019-03-18 - * - */ -public class InvokeOriginTest { - - ClassNode apmClassNode; - ClassNode originClassNode; - - ClassNode targetClassNode; - - @Rule - public TestName testName = new TestName(); - - @BeforeClass - public static void beforeClass() throws IOException { - - } - - @Before - public void before() throws IOException { - apmClassNode = AsmUtils.loadClass(InvokeOriginDemo_APM.class); - originClassNode = AsmUtils.loadClass(InvokeOriginDemo.class); - - byte[] renameClass = AsmUtils.renameClass(AsmUtils.toBytes(apmClassNode), - Type.getObjectType(originClassNode.name).getClassName()); - - apmClassNode = AsmUtils.toClassNode(renameClass); - - targetClassNode = AsmUtils.copy(originClassNode); - } - - private Object replace(String methodName) throws Exception { - System.err.println(methodName); - for (MethodNode methodNode : apmClassNode.methods) { - if (methodNode.name.equals(methodName)) { - methodNode = AsmUtils.removeLineNumbers(methodNode); - // 从原来的类里查找对应的函数 - MethodNode findMethod = AsmUtils.findMethod(originClassNode.methods, methodNode); - if (findMethod != null) { - MethodNode methodNode2 = InstrumentImpl.replaceInvokeOrigin(originClassNode.name, findMethod, - methodNode); - - System.err.println(Decompiler.toString(methodNode2)); - - AsmUtils.replaceMethod(targetClassNode, methodNode2); - - } else { - - } - } - } - - byte[] resutlBytes = AsmUtils.toBytes(targetClassNode); - - System.err.println("================="); - - System.err.println(Decompiler.decompile(resutlBytes)); - - // System.err.println(AsmUtils.toASMCode(resutlBytes)); - - VerifyUtils.asmVerify(resutlBytes); - return VerifyUtils.instanceVerity(resutlBytes); - } - - @Test - public void test_returnVoid() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).isEqualTo(null); - } - - @Test - public void test_returnVoidObject() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).isEqualTo(null); - } - - @Test - public void test_returnInt() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName, 123)).isEqualTo(9998 + 123); - } - - @Test - public void test_returnIntToObject() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName, 123)).isEqualTo(9998 + 9998); - } - - @Test - public void test_returnIntToInteger() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName, 123)).isEqualTo(9998 + 9998); - } - - @Test - public void test_returnIntStatic() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName, 123)).isEqualTo(9998 + 9998); - } - - @Test - public void test_returnLong() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).isEqualTo(9998L + 9998); - } - - @Test - public void test_returnLongToObject() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).isEqualTo(9998L + 9998); - } - - @Test - public void test_returnStrArray() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).isEqualTo(new String[] { "abc", "xyz", "ufo" }); - } - - @Test - public void test_returnStrArrayWithArgs() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName, 123, "sss", 777L)) - .isEqualTo(new Object[] { "fff", "xyz" + "sss", "ufo" + 777 }); - } - - @Test - public void test_returnStr() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).asString().startsWith("hello"); - } - - @Test - public void test_returnObject() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName)).isEqualTo(object.getClass()); - } - - @Test - public void test_recursive() throws Exception { - String methodName = testName.getMethodName().substring("test_".length()); - Object object = replace(methodName); - Assertions.assertThat(VerifyUtils.invoke(object, methodName, 100)).isEqualTo((100 + 1) * 100 / 2); - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtEnterTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtEnterTest.java deleted file mode 100644 index a90dc7177..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtEnterTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtEnterTest { - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @Rule - public OutputCapture capture = new OutputCapture(); - - public static class Sample { - - long longField; - String strField; - static int intField; - - public int hello(String str, boolean exception) { - if (exception) { - throw new RuntimeException("test exception"); - } - return str.length(); - } - - public long toBeInvoke(int i , long l, String s, long ll) { - return l + ll; - } - - public void testInvokeArgs() { - toBeInvoke(1, 123L, "abc", 100L); - } - - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = true) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class EnterInterceptor { - - @AtEnter(inline = true - , suppress = RuntimeException.class, suppressHandler = TestPrintSuppressHandler.class - ) - public static long onEnter( - @Binding.This Object object, @Binding.Class Object clazz, - @Binding.Field(name = "longField") long longField, - @Binding.Field(name = "longField") Object longFieldObject, - @Binding.Field(name = "intField") int intField, - @Binding.Field(name = "strField") String strField, - @Binding.Field(name = "intField") Object intFielObject, - @Binding.MethodName String methodName, - @Binding.MethodDesc String methodDesc - ) { - System.err.println("onEnter, object:" + object); - System.err.println("onEnter, methodName:" + methodName); - System.err.println("onEnter, methodDesc:" + methodDesc); - return 123L; - } - - } - - - - @Test - public void testEnter() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(EnterInterceptor.class).methodMatcher("hello") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - new Sample().hello("abc", false); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("onEnter, object:"); - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtExceptionExitTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtExceptionExitTest.java deleted file mode 100644 index 323e85863..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtExceptionExitTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtExceptionExitTest { - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @Rule - public OutputCapture capture = new OutputCapture(); - - public static class Sample { - - long longField; - String strField; - static int intField; - - public int hello(String str, boolean exception) { - if (exception) { - throw new RuntimeException("test exception"); - } - return str.length(); - } - - public long toBeInvoke(int i , long l, String s, long ll) { - return l + ll; - } - - public void testInvokeArgs() { - toBeInvoke(1, 123L, "abc", 100L); - } - - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = true) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - System.err.println(e.getMessage()); - assertThat(e).hasMessage("exception for ExceptionHandler"); - } - } - - public static class ExceptionExitInterceptor { - @AtExceptionExit(inline = false, onException = RuntimeException.class ,suppress = Throwable.class, suppressHandler = TestPrintSuppressHandler.class) - public static void onExceptionExit(@Binding.Throwable RuntimeException ex, @Binding.This Object object, - @Binding.Class Object clazz) { - System.err.println("AtExceptionExit, ex:" + ex); - throw new RuntimeException("exception for ExceptionHandler"); - } - } - - - @Test - public void testExecptionExitException() throws Exception { - - TestHelper helper = TestHelper.builder().interceptorClass(ExceptionExitInterceptor.class).methodMatcher("hello") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - System.err.println(Decompiler.decompile(bytes)); - try { - new Sample().hello("abc", true); - } catch (Exception e) { - assertThat(e).isInstanceOf(RuntimeException.class).hasMessageContaining("test exception"); - } - - assertThat(capture.toString()).contains("AtExceptionExit, ex:"); - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtExitTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtExitTest.java deleted file mode 100644 index 1462500ad..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtExitTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtExitTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - static class Sample { - long longField; - int intField; - String strField; - - public void voidExit() { - - } - - public long longExit() { - return 100L; - } - - public static long staticExit() { - return 999L; - } - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = false) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class TestAccessInterceptor { - @AtExit(inline = false) - public static void atExit(@Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.Return Object re - ) { - System.err.println("AtFieldAccess: this" + object); - } - } - - public static class ChangeReturnInterceptor { - - @AtExit(inline = false, suppress = RuntimeException.class, suppressHandler = TestPrintSuppressHandler.class) - public static Object onExit(@Binding.This Object object, @Binding.Class Object clazz) { - System.err.println("onExit, object:" + object); - return 123L; - } - } - - @Test - public void testExit() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(TestAccessInterceptor.class).methodMatcher("voidExit") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - new Sample().voidExit(); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("AtFieldAccess: this"); - } - - - @Test - public void testExitAndChangeReturn() throws Exception { - - TestHelper helper = TestHelper.builder().interceptorClass(ChangeReturnInterceptor.class).methodMatcher("longExit") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - System.err.println(Decompiler.decompile(bytes)); - - long re = new Sample().longExit(); - - assertThat(re).isEqualTo(123); - assertThat(capture.toString()).contains("onExit, object:"); - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtFieldAccessTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtFieldAccessTest.java deleted file mode 100644 index 45024ce2d..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtFieldAccessTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtFieldAccess; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtFieldAccessTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - class Sample { - long longField; - int intField; - String strField; - - public int testReadField(int ii) { - longField = 999; - return 123; - } - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = false) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class FieldAccessInterceptor { - @AtFieldAccess(name = "longField" , inline =false) - public static void onFieldAccess(@Binding.This Object object, - @Binding.Class Object clazz) { - System.err.println("AtFieldAccess: this" + object); - } - } - - @Test - public void testEnter() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(FieldAccessInterceptor.class).methodMatcher("testReadField") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - new Sample().testReadField(100); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("AtFieldAccess: this"); - } - - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtInvokeTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtInvokeTest.java deleted file mode 100644 index f6c565829..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtInvokeTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvoke; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtInvokeTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - static class Sample { - long longField; - int intField; - String strField; - - public Sample(int i, long l, String s) { - staticToBeCall(i, l, s); - aaa("aaa"); - } - - public int testCall(int ii) { - toBeCall(ii, 123L, ""); - System.err.println("abc"); - - aaa("abc"); - return 123; - } - - - public void aaa(String aaa) { - return ; - } - - public long toBeCall(int i , long l, String s) { - return l + i; - } - - public static long staticToBeCall(int i , long l, String s) { - return l + i; - } - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = false) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class TestAccessInterceptor { - @AtInvoke(name = "", inline = false, whenComplete=false, excludes = {"System."}) - public static void onInvoke( - @Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.Line int line, - @Binding.InvokeArgs Object[] args - ) { - System.err.println("onInvoke: line: " + line); - System.err.println("onInvoke: this: " + object); - } - - @AtInvoke(name = "toBeCall", inline = false, whenComplete = true) - public static void onInvokeAfter( - @Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.InvokeReturn Object invokeReturn - , - @Binding.InvokeMethodDeclaration String declaration - ) { - System.err.println("onInvokeAfter: this" + object); - System.err.println("declaration: " + declaration); - assertThat(declaration).isEqualTo("long toBeCall(int, long, java.lang.String)"); - - System.err.println("invokeReturn: " + invokeReturn); - assertThat(invokeReturn).isEqualTo(100 + 123L); - } - } - - //@Test - // TODO fix com.taobao.arthas.bytekit.asm.location.Location.InvokeLocation satck save - public void testInvokeBefore() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(TestAccessInterceptor.class).methodMatcher("testCall") - .redefine(true); - byte[] bytes = helper.process(Sample.class); - - new Sample(100, 100L, "").testCall(100); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("onInvoke: this"); - } - - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtLineTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtLineTest.java deleted file mode 100644 index 2bcba1672..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtLineTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtLine; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtLineTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - static class Sample { - - public int testLine(int i) { - String s = "" + i; - if(i > 0) { - String abc = s + i; - i++; - i = i * 100 - + i - - 100 + Math.max(100, i); - i += s.length() + abc.length(); - }else { - if(i == -1) { - try { - System.err.println("i is -1"); - throw new RuntimeException(); - } catch (Exception e) { - System.err.println(e.getMessage()); - } - - } - } - return i * 2; - } - - } - - public static class TestAccessInterceptor { - - @AtLine(lines = { -1}, inline = false) - public static void atLine( - @Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.Line int line, - @Binding.Args Object[] args - , - @Binding.ArgNames String[] argNames - , - @Binding.LocalVars Object[] vars, - @Binding.LocalVarNames String[] varNames - ) { - System.err.println("atLine: this" + object); - System.err.println("line: " + line); - System.err.println("args: " + Arrays.toString(args)); - System.err.println("argNames: " + Arrays.toString(argNames)); - - System.err.println("vars: " + Arrays.toString(vars)); - System.err.println("varNames: " + Arrays.toString(varNames)); - } - } - - @Test - public void testLine() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(TestAccessInterceptor.class).methodMatcher("*") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - new Sample().testLine(100); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("atLine: this"); - } - - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtSyncEnterTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtSyncEnterTest.java deleted file mode 100644 index 91ccbb512..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtSyncEnterTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtSyncEnter; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtSyncEnterTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - static class Sample { - - public int testLine(int i) { - String s = "" + i; - synchronized (s) { - if(i > 0) { - String abc = s + i; - i++; - i = i * 100 - + i - - 100 + Math.max(100, i); - i += s.length() + abc.length(); - }else { - if(i == -1) { - try { - System.err.println("i is -1"); - throw new RuntimeException(); - } catch (Exception e) { - System.err.println(e.getMessage()); - } - - } - } - } - - return i * 2; - } - - } - - public static class TestInterceptor { - - @AtSyncEnter(whenComplete=false, inline = false) - public static void atSyncEnter( - @Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.Args Object[] args - , - @Binding.ArgNames String[] argNames - , - @Binding.LocalVars Object[] vars, - @Binding.LocalVarNames String[] varNames - , - @Binding.Monitor Object monitor - ) { - System.err.println("atSyncEnter: this" + object); - System.err.println("args: " + Arrays.toString(args)); - System.err.println("argNames: " + Arrays.toString(argNames)); - - System.err.println("vars: " + Arrays.toString(vars)); - System.err.println("varNames: " + Arrays.toString(varNames)); - - } - } - - @Test - public void test() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(TestInterceptor.class).methodMatcher("*") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - new Sample().testLine(100); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("atSyncEnter: this"); - } - - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtSyncExitTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtSyncExitTest.java deleted file mode 100644 index 9aef147d4..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtSyncExitTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtSyncExit; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtSyncExitTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - static class Sample { - - public int testLine(int i) { - String s = "" + i; - synchronized (s) { - if(i > 0) { - String abc = s + i; - i++; - i = i * 100 - + i - - 100 + Math.max(100, i); - i += s.length() + abc.length(); - }else { - if(i == -1) { - try { - System.err.println("i is -1"); - throw new RuntimeException(); - } catch (Exception e) { - System.err.println(e.getMessage()); - } - - } - } - } - - return i * 2; - } - - } - - public static class TestInterceptor { - - @AtSyncExit(whenComplete=false, inline = false) - public static void atSyncExit( - @Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.Args Object[] args - , - @Binding.ArgNames String[] argNames - , - @Binding.LocalVars Object[] vars, - @Binding.LocalVarNames String[] varNames - , - @Binding.Monitor Object monitor - ) { - System.err.println("atSyncExit: this" + object); - System.err.println("args: " + Arrays.toString(args)); - System.err.println("argNames: " + Arrays.toString(argNames)); - - System.err.println("vars: " + Arrays.toString(vars)); - System.err.println("varNames: " + Arrays.toString(varNames)); - - } - } - - @Test - public void test() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(TestInterceptor.class).methodMatcher("*") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - new Sample().testLine(100); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("atSyncExit: this"); - } - - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtThrowTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtThrowTest.java deleted file mode 100644 index d696ca978..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/AtThrowTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; - -import org.junit.Rule; -import org.junit.Test; -import org.springframework.boot.test.rule.OutputCapture; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtThrow; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; - -public class AtThrowTest { - @Rule - public OutputCapture capture = new OutputCapture(); - - static class Sample { - - public static long testThrow(int i , long l, String s) { - try { - if(i < 0) { - throw new RuntimeException("eeeee"); - } - } catch (Exception e) { - - System.err.println(e.getMessage()); - } - return l + i; - } - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = false) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class TestAccessInterceptor { - - @AtThrow(inline = false) - public static void atThrow( - @Binding.This Object object, - @Binding.Class Object clazz - , - @Binding.LocalVars Object[] vars, - @Binding.Throwable Throwable t - ) { - System.err.println("atThrow: this" + object); - System.err.println("vars: " + Arrays.toString(vars)); - System.err.println("t: " + t); - - assertThat(t).hasMessage("eeeee"); - } - } - - @Test - public void testThrow() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(TestAccessInterceptor.class).methodMatcher("testThrow") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - Sample.testThrow(-1, 0, null); - - System.err.println(Decompiler.decompile(bytes)); - - assertThat(capture.toString()).contains("atThrow: this"); - } - - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/InlineWhileTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/InlineWhileTest.java deleted file mode 100644 index 0175799b5..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/InlineWhileTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.ExceptionHandler; -import com.taobao.arthas.bytekit.utils.Decompiler; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.springframework.boot.test.rule.OutputCapture; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * testcase for IINC - */ -public class InlineWhileTest { - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - - @Rule - public OutputCapture capture = new OutputCapture(); - - public static class Sample { - - public int hello(String str, boolean exception) { - if (exception) { - throw new RuntimeException("test exception"); - } - return str.length(); - } - } - - public static class TestPrintSuppressHandler { - - @ExceptionHandler(inline = true) - public static void onSuppress(@Binding.Throwable Throwable e, @Binding.Class Object clazz) { - System.err.println("exception handler: " + clazz); - e.printStackTrace(); - } - } - - public static class EnterInterceptor { - - @AtEnter(inline = true, - suppress = RuntimeException.class, - suppressHandler = TestPrintSuppressHandler.class - ) - public static long onEnter( - @Binding.This Object object, @Binding.Class Object clazz, - @Binding.MethodName String methodName, - @Binding.MethodDesc String methodDesc - ) { - System.err.println("onEnter, object:" + object); - System.err.println("onEnter, methodName:" + methodName); - System.err.println("onEnter, methodDesc:" + methodDesc); - - int i=0; - while (i++ < 3) { - System.err.println("enter: "+i); - } - return 123L; - } - - @AtExit(inline = true, - suppress = RuntimeException.class, - suppressHandler = TestPrintSuppressHandler.class - ) - public static void onExit( - @Binding.This Object object, @Binding.Class Object clazz, - @Binding.MethodName String methodName, - @Binding.MethodDesc String methodDesc - ) { - System.err.println("onExit, object:" + object); - System.err.println("onExit, methodName:" + methodName); - System.err.println("onExit, methodDesc:" + methodDesc); - - int i=0; - while (i++ < 3) { - System.err.println("exit: "+i); - } - } - - @AtExceptionExit - public static void onException(@Binding.This Object object, @Binding.Class Object clazz, - @Binding.MethodName String methodName, - @Binding.MethodDesc String methodDesc, - @Binding.Throwable Throwable ex) { - System.err.println("onException: "+ex); - int i=0; - i+=3; - System.err.println("exception: "+i); - } - } - - - - @Test - public void test1() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(EnterInterceptor.class).methodMatcher("hello") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - System.err.println(Decompiler.decompile(bytes)); - - new Sample().hello("abc", false); - - String actual = capture.toString(); - assertThat(actual).contains("onEnter, object:"); - assertThat(actual).contains("enter: 3"); - assertThat(actual).contains("onExit, object:"); - assertThat(actual).contains("exit: 3"); - - - } - - @Test - public void test2() throws Exception { - TestHelper helper = TestHelper.builder().interceptorClass(EnterInterceptor.class).methodMatcher("hello") - .reTransform(true); - byte[] bytes = helper.process(Sample.class); - - System.err.println(Decompiler.decompile(bytes)); - - try { - new Sample().hello("abc", true); - } catch (Exception e) { - e.printStackTrace(); - } - - String actual = capture.toString(); - assertThat(actual).contains("onEnter, object:"); - assertThat(actual).contains("enter: 3"); - assertThat(actual).contains("onException: java.lang.RuntimeException: test exception"); - assertThat(actual).contains("exception: 3"); - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/TestHelper.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/TestHelper.java deleted file mode 100644 index aff87158b..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/interceptor/TestHelper.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.taobao.arthas.bytekit.asm.interceptor; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.utils.AgentUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.MatchUtils; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -/** - * - * @author hengyunabc - * - */ -public class TestHelper { - - private Class interceptorClass; - - private boolean redefine; - - private boolean reTransform; - - private String methodMatcher = "*"; - - private boolean asmVerity = true; - - public static TestHelper builder() { - return new TestHelper(); - } - - public TestHelper interceptorClass(Class interceptorClass) { - this.interceptorClass = interceptorClass; - return this; - } - - public TestHelper redefine(boolean redefine) { - this.redefine = redefine; - return this; - } - - public TestHelper reTransform(boolean reTransform) { - this.reTransform = reTransform; - return this; - } - - public TestHelper methodMatcher(String methodMatcher) { - this.methodMatcher = methodMatcher; - return this; - } - - public byte[] process(Class transform) throws Exception { - DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); - - List interceptorProcessors = defaultInterceptorClassParser.parse(interceptorClass); - - ClassNode classNode = AsmUtils.loadClass(transform); - - List matchedMethods = new ArrayList(); - for (MethodNode methodNode : classNode.methods) { - if (MatchUtils.wildcardMatch(methodNode.name, methodMatcher)) { - matchedMethods.add(methodNode); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - byte[] bytes = AsmUtils.toBytes(classNode); - if (asmVerity) { - VerifyUtils.asmVerify(bytes); - } - - if (redefine) { - AgentUtils.redefine(transform, bytes); - } - - if (reTransform) { - AgentUtils.reTransform(transform, bytes); - } - - return bytes; - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/GroupFilterTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/GroupFilterTest.java deleted file mode 100644 index 9aa9cae02..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/GroupFilterTest.java +++ /dev/null @@ -1,318 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import java.util.ArrayList; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.junit.Test; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvoke; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvokeException; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.asm.location.LocationType; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; -import com.taobao.arthas.bytekit.utils.MatchUtils; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class GroupFilterTest { - - public static class SpyInterceptor { - - @AtEnter(inline = true) - public static void atEnter(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc, - @Binding.Args Object[] args) { - SpyAPI.atEnter(clazz, methodName, methodDesc, target, args); - } - - @AtExit(inline = true) - public static void atExit(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc, - @Binding.Args Object[] args, @Binding.Return Object returnObj) { - SpyAPI.atExit(clazz, methodName, methodDesc, target, args, returnObj); - } - - @AtExceptionExit(inline = true) - public static void atExceptionExit(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc, - @Binding.Args Object[] args, @Binding.Throwable Throwable throwable) { - SpyAPI.atExceptionExit(clazz, methodName, methodDesc, target, args, throwable); - } - } - - public static class SpyTraceInterceptor { - @AtInvoke(name = "", inline = true, whenComplete = false, excludes = { "java.**", "**SpyAPI**" }) - public static void onInvoke(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeInfo String invokeInfo) { - SpyAPI.atBeforeInvoke(clazz, invokeInfo, target); - } - - @AtInvoke(name = "", inline = true, whenComplete = true, excludes = { "java.**", "**SpyAPI**" }) - public static void onInvokeAfter(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeInfo String invokeInfo) { - SpyAPI.atAfterInvoke(clazz, invokeInfo, target); - } - - @AtInvokeException(name = "", inline = true, excludes = { "java.**", "**SpyAPI**" }) - public static void onInvokeException(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeInfo String invokeInfo, @Binding.Throwable Throwable throwable) { - SpyAPI.atInvokeException(clazz, invokeInfo, target, throwable); - } - } - - public static class SpyTraceInterceptor2 { - @AtInvoke(name = "", inline = true, whenComplete = false, excludes = { "**SpyAPI**" }) - public static void onInvoke(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeInfo String invokeInfo) { - - SpyAPI.atBeforeInvoke(clazz, invokeInfo, target); - } - - @AtInvoke(name = "", inline = true, whenComplete = true, excludes = { "**SpyAPI**" }) - public static void onInvokeAfter(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeInfo String invokeInfo) { - SpyAPI.atAfterInvoke(clazz, invokeInfo, target); - } - - @AtInvokeException(name = "", inline = true, excludes = { "**SpyAPI**" }) - public static void onInvokeException(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeInfo String invokeInfo, @Binding.Throwable Throwable throwable) { - SpyAPI.atInvokeException(clazz, invokeInfo, target, throwable); - } - } - - public static class SpyAPI { - public static void atEnter(Class clazz, String methodName, String methodDesc, Object target, Object[] args) { - - } - - public static void atExceptionExit(Class clazz, String methodName, String methodDesc, Object target, - Object[] args, Throwable throwable) { - - } - - public static void atExit(Class clazz, String methodName, String methodDesc, Object target, Object[] args, - Object returnObj) { - - } - - public static void atBeforeInvoke(Class clazz, String invokeInfo, - Object target) { - - } - - public static void atInvokeException(Class clazz, String invokeInfo, - Object target, Throwable throwable) { - - } - - public static void atAfterInvoke(Class clazz, String invokeInfo, - Object target) { - - } - - } - - public static class TestAAA { - - int i = 0; - long l = 0; - - public TestAAA() { - xxx(1, 134L); - } - - public String hello(String str) { - - String result = ""; - - xxx(i, l); - - return result; - - } - - public String xxx(int i, long l) { - return "" + i + l; - } - - } - - @Test - public void test() throws Exception { - boolean skipJDKTrace = false; - - DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); - - List interceptorProcessors = defaultInterceptorClassParser - .parse(SpyInterceptor.class); - - Class spyTraceInterceptorClass = SpyTraceInterceptor2.class; - if (skipJDKTrace == false) { - spyTraceInterceptorClass = SpyTraceInterceptor.class; - } - List traceInvokeProcessors = defaultInterceptorClassParser - .parse(spyTraceInterceptorClass); - interceptorProcessors.addAll(traceInvokeProcessors); - - - ClassNode classNode = AsmUtils.loadClass(TestAAA.class); - - List matchedMethods = new ArrayList(); - for (MethodNode methodNode : classNode.methods) { - if (MatchUtils.wildcardMatch(methodNode.name, "*")) { - matchedMethods.add(methodNode); - } - } - - GroupLocationFilter groupLocationFilter = new GroupLocationFilter(); - - LocationFilter enterFilter = new InvokeContainLocationFilter(Type.getInternalName(SpyAPI.class), "atEnter", - LocationType.ENTER); - LocationFilter existFilter = new InvokeContainLocationFilter(Type.getInternalName(SpyAPI.class), "atExit", - LocationType.EXIT); - LocationFilter exceptionFilter = new InvokeContainLocationFilter(Type.getInternalName(SpyAPI.class), - "atExceptionExit", LocationType.EXCEPTION_EXIT); - - groupLocationFilter.addFilter(enterFilter); - groupLocationFilter.addFilter(existFilter); - groupLocationFilter.addFilter(exceptionFilter); - - LocationFilter invokeBeforeFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), "atBeforeInvoke", - LocationType.INVOKE); - LocationFilter invokeAfterFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_COMPLETED); - LocationFilter invokeExceptionFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_EXCEPTION_EXIT); - groupLocationFilter.addFilter(invokeBeforeFilter); - groupLocationFilter.addFilter(invokeAfterFilter); - groupLocationFilter.addFilter(invokeExceptionFilter); - - - for(int i = 0 ; i < 20 ; ++i) { - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - } - - - byte[] bytes = AsmUtils.toBytes(classNode); - VerifyUtils.asmVerify(bytes); - - VerifyUtils.instanceVerity(bytes); - - System.out.println(Decompiler.decompile(bytes)); - - ClassNode classNode2 = AsmUtils.toClassNode(bytes); - for (MethodNode methodNode : classNode2.methods) { - if (!methodNode.name.equals("xxx")) { - System.err.println("method name: " + methodNode.name); - Assertions.assertThat( - AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atBeforeInvoke")) - .size().isEqualTo(1); - } - } - - } - - @Test - public void test2() throws Exception { - - DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); - - List interceptorProcessors = defaultInterceptorClassParser - .parse(SpyTraceInterceptor2.class); - - ClassNode classNode = AsmUtils.loadClass(TestAAA.class); - - List matchedMethods = new ArrayList(); - for (MethodNode methodNode : classNode.methods) { - if (MatchUtils.wildcardMatch(methodNode.name, "*")) { - matchedMethods.add(methodNode); - } - } - - LocationFilter enterFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), "atBeforeInvoke", - LocationType.INVOKE); - LocationFilter existFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_COMPLETED); - LocationFilter exceptionFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_EXCEPTION_EXIT); - GroupLocationFilter groupLocationFilter = new GroupLocationFilter(); - groupLocationFilter.addFilter(enterFilter); - groupLocationFilter.addFilter(existFilter); - groupLocationFilter.addFilter(exceptionFilter); - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - byte[] bytes = AsmUtils.toBytes(classNode); - VerifyUtils.asmVerify(bytes); - - VerifyUtils.instanceVerity(bytes); - - System.out.println(Decompiler.decompile(bytes)); - - ClassNode classNode2 = AsmUtils.toClassNode(bytes); - for (MethodNode methodNode : classNode2.methods) { - if (!methodNode.name.equals("xxx")) { - System.err.println("method name: " + methodNode.name); - Assertions.assertThat( - AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atBeforeInvoke")) - .size().isEqualTo(1); - } - } - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeCheckLocationFilterTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeCheckLocationFilterTest.java deleted file mode 100644 index 7fd58688d..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeCheckLocationFilterTest.java +++ /dev/null @@ -1,258 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import java.util.ArrayList; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.junit.Test; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvoke; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvokeException; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.asm.location.LocationType; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; -import com.taobao.arthas.bytekit.utils.MatchUtils; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class InvokeCheckLocationFilterTest { - - public static class SpyTraceInterceptor { - @AtInvoke(name = "", inline = true, whenComplete = false, excludes = { "java.**", "**SpyAPI**" }) - public static void onInvoke(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeMethodDeclaration String methodDesc, @Binding.InvokeMethodOwner String owner, - @Binding.InvokeMethodName String methodName) { - SpyAPI.atBeforeInvoke(clazz, owner, methodName, methodDesc, target); - } - - @AtInvoke(name = "", inline = true, whenComplete = true, excludes = { "java.**", "**SpyAPI**" }) - public static void onInvokeAfter(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeMethodDeclaration String methodDesc, @Binding.InvokeMethodOwner String owner, - @Binding.InvokeMethodName String methodName) { - SpyAPI.atAfterInvoke(clazz, owner, methodName, methodDesc, target); - } - - @AtInvokeException(name = "", inline = true, excludes = { "java.**", "**SpyAPI**" }) - public static void onInvokeException(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeMethodDeclaration String methodDesc, @Binding.InvokeMethodOwner String owner, - @Binding.InvokeMethodName String methodName, @Binding.Throwable Throwable throwable) { - SpyAPI.atInvokeException(clazz, owner, methodName, methodDesc, target, throwable); - } - } - - public static class SpyTraceInterceptor2 { - @AtInvoke(name = "", inline = true, whenComplete = false, excludes = { "**SpyAPI**" }) - public static void onInvoke(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeMethodDeclaration String methodDesc, @Binding.InvokeMethodOwner String owner, - @Binding.InvokeMethodName String methodName) { - SpyAPI.atBeforeInvoke(clazz, owner, methodName, methodDesc, target); - } - - @AtInvoke(name = "", inline = true, whenComplete = true, excludes = { "**SpyAPI**" }) - public static void onInvokeAfter(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeMethodDeclaration String methodDesc, @Binding.InvokeMethodOwner String owner, - @Binding.InvokeMethodName String methodName) { - SpyAPI.atAfterInvoke(clazz, owner, methodName, methodDesc, target); - } - - @AtInvokeException(name = "", inline = true, excludes = { "**SpyAPI**" }) - public static void onInvokeException(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.InvokeMethodDeclaration String methodDesc, @Binding.InvokeMethodOwner String owner, - @Binding.InvokeMethodName String methodName, @Binding.Throwable Throwable throwable) { - SpyAPI.atInvokeException(clazz, owner, methodName, methodDesc, target, throwable); - } - } - - public static class SpyAPI { - - public static void atBeforeInvoke(Class clazz, String owner, String methodName, String methodDesc, - Object target) { - - } - - public static void atInvokeException(Class clazz, String owner, String methodName, String methodDesc, - Object target, Throwable throwable) { - - } - - public static void atAfterInvoke(Class clazz, String owner, String methodName, String methodDesc, - Object target) { - - } - - } - - public static class TestAAA { - - int i = 0; - long l = 0; - - public TestAAA() { - xxx(1, 134L); - } - - public String hello(String str) { - - String result = ""; - - xxx(i, l); - - return result; - - } - - public String xxx(int i, long l) { - return "" + i + l; - } - - } - - @Test - public void test() throws Exception { - - DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); - - List interceptorProcessors = defaultInterceptorClassParser - .parse(SpyTraceInterceptor.class); - - ClassNode classNode = AsmUtils.loadClass(TestAAA.class); - - List matchedMethods = new ArrayList(); - for (MethodNode methodNode : classNode.methods) { - if (MatchUtils.wildcardMatch(methodNode.name, "*")) { - matchedMethods.add(methodNode); - } - } - - LocationFilter enterFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), "atBeforeInvoke", - LocationType.INVOKE); - LocationFilter existFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_COMPLETED); - LocationFilter exceptionFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_EXCEPTION_EXIT); - GroupLocationFilter groupLocationFilter = new GroupLocationFilter(); - groupLocationFilter.addFilter(enterFilter); - groupLocationFilter.addFilter(existFilter); - groupLocationFilter.addFilter(exceptionFilter); - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - byte[] bytes = AsmUtils.toBytes(classNode); - VerifyUtils.asmVerify(bytes); - - VerifyUtils.instanceVerity(bytes); - - System.out.println(Decompiler.decompile(bytes)); - - ClassNode classNode2 = AsmUtils.toClassNode(bytes); - for (MethodNode methodNode : classNode2.methods) { - if (!methodNode.name.equals("xxx")) { - System.err.println("method name: " + methodNode.name); - Assertions.assertThat( - AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atBeforeInvoke")) - .size().isEqualTo(1); - } - } - - } - - - @Test - public void test2() throws Exception { - - DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); - - List interceptorProcessors = defaultInterceptorClassParser - .parse(SpyTraceInterceptor2.class); - - ClassNode classNode = AsmUtils.loadClass(TestAAA.class); - - List matchedMethods = new ArrayList(); - for (MethodNode methodNode : classNode.methods) { - if (MatchUtils.wildcardMatch(methodNode.name, "*")) { - matchedMethods.add(methodNode); - } - } - - LocationFilter enterFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), "atBeforeInvoke", - LocationType.INVOKE); - LocationFilter existFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_COMPLETED); - LocationFilter exceptionFilter = new InvokeCheckLocationFilter(Type.getInternalName(SpyAPI.class), - "atInvokeException", LocationType.INVOKE_EXCEPTION_EXIT); - GroupLocationFilter groupLocationFilter = new GroupLocationFilter(); - groupLocationFilter.addFilter(enterFilter); - groupLocationFilter.addFilter(existFilter); - groupLocationFilter.addFilter(exceptionFilter); - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - byte[] bytes = AsmUtils.toBytes(classNode); - VerifyUtils.asmVerify(bytes); - - VerifyUtils.instanceVerity(bytes); - - System.out.println(Decompiler.decompile(bytes)); - - ClassNode classNode2 = AsmUtils.toClassNode(bytes); - for (MethodNode methodNode : classNode2.methods) { - if (!methodNode.name.equals("xxx")) { - System.err.println("method name: " + methodNode.name); - Assertions.assertThat( - AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atBeforeInvoke")) - .size().isEqualTo(1); - } - } - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeContainLocationFilterTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeContainLocationFilterTest.java deleted file mode 100644 index 6b12eb9b0..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/asm/location/filter/InvokeContainLocationFilterTest.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.taobao.arthas.bytekit.asm.location.filter; - -import java.util.ArrayList; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.junit.Test; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.binding.Binding; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit; -import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.asm.location.LocationType; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; -import com.taobao.arthas.bytekit.utils.MatchUtils; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class InvokeContainLocationFilterTest { - - public static class SpyInterceptor { - - @AtEnter(inline = true) - public static void atEnter(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc, - @Binding.Args Object[] args) { - SpyAPI.atEnter(clazz, methodName, methodDesc, target, args); - } - - @AtExit(inline = true) - public static void atExit(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc, - @Binding.Args Object[] args, @Binding.Return Object returnObj) { - SpyAPI.atExit(clazz, methodName, methodDesc, target, args, returnObj); - } - - @AtExceptionExit(inline = true) - public static void atExceptionExit(@Binding.This Object target, @Binding.Class Class clazz, - @Binding.MethodName String methodName, @Binding.MethodDesc String methodDesc, - @Binding.Args Object[] args, @Binding.Throwable Throwable throwable) { - SpyAPI.atExceptionExit(clazz, methodName, methodDesc, target, args, throwable); - } - } - - public static class SpyAPI { - - public static void atEnter(Class clazz, String methodName, String methodDesc, Object target, Object[] args) { - - } - - public static void atExceptionExit(Class clazz, String methodName, String methodDesc, Object target, - Object[] args, Throwable throwable) { - - } - - public static void atExit(Class clazz, String methodName, String methodDesc, Object target, Object[] args, - Object returnObj) { - - } - - } - - public static class TestAAA { - - int i = 0; - long l = 0; - - public String hello(String str) { - - String result = ""; - - xxx(i, l); - - return result; - - } - - public String xxx(int i, long l) { - return "" + i + l; - } - - } - - @Test - public void test() throws Exception { - - DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); - - List interceptorProcessors = defaultInterceptorClassParser.parse(SpyInterceptor.class); - - ClassNode classNode = AsmUtils.loadClass(TestAAA.class); - - List matchedMethods = new ArrayList(); - for (MethodNode methodNode : classNode.methods) { - if (MatchUtils.wildcardMatch(methodNode.name, "*")) { - matchedMethods.add(methodNode); - } - } - - LocationFilter enterFilter = new InvokeContainLocationFilter(Type.getInternalName(SpyAPI.class), "atEnter", - LocationType.ENTER); - LocationFilter existFilter = new InvokeContainLocationFilter(Type.getInternalName(SpyAPI.class), "atExit", - LocationType.EXIT); - LocationFilter exceptionFilter = new InvokeContainLocationFilter(Type.getInternalName(SpyAPI.class), - "atExceptionExit", LocationType.EXCEPTION_EXIT); - GroupLocationFilter groupLocationFilter = new GroupLocationFilter(); - groupLocationFilter.addFilter(enterFilter); - groupLocationFilter.addFilter(existFilter); - groupLocationFilter.addFilter(exceptionFilter); - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - for (MethodNode methodNode : matchedMethods) { - MethodProcessor methodProcessor = new MethodProcessor(classNode, methodNode, groupLocationFilter); - for (InterceptorProcessor interceptor : interceptorProcessors) { - interceptor.process(methodProcessor); - } - } - - byte[] bytes = AsmUtils.toBytes(classNode); - VerifyUtils.asmVerify(bytes); - - System.out.println(Decompiler.decompile(bytes)); - - ClassNode classNode2 = AsmUtils.toClassNode(bytes); - for (MethodNode methodNode : classNode2.methods) { - System.err.println("method name: " + methodNode.name); - Assertions - .assertThat(AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atEnter")) - .size().isEqualTo(1); - Assertions - .assertThat(AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atExit")) - .size().isEqualTo(1); - Assertions - .assertThat(AsmUtils.findMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atExceptionExit")) - .size().isEqualTo(1); - } - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/AsmAnnotationUtilsTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/AsmAnnotationUtilsTest.java deleted file mode 100644 index 366fac9a7..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/AsmAnnotationUtilsTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.io.IOException; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.Arrays; - -import org.assertj.core.api.Assertions; -import org.junit.Test; -import org.springframework.stereotype.Service; - -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.taobao.arthas.bytekit.utils.AsmAnnotationUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; - -/** - * - * @author hengyunabc 2020-05-04 - * - */ -public class AsmAnnotationUtilsTest { - - @Target(value = { ElementType.TYPE, ElementType.METHOD }) - @Retention(value = RetentionPolicy.RUNTIME) - public @interface AdviceInfo { - - public String[] adviceInfos(); - } - - @Service - @AdviceInfo(adviceInfos = { "xxxx", "yyy" }) - static class AAA { - - @AdviceInfo(adviceInfos = { "mmm", "yyy" }) - public void test() { - - } - - } - - @Service - static class BBB { - public void test() { - } - } - - @Test - public void test() throws IOException { - ClassNode classNodeA = AsmUtils.loadClass(AAA.class); - - ClassNode classNodeB = AsmUtils.loadClass(BBB.class); - - Assertions.assertThat(AsmAnnotationUtils.queryAnnotationInfo(classNodeA.visibleAnnotations, - Type.getDescriptor(AdviceInfo.class), "adviceInfos")).isEqualTo(Arrays.asList("xxxx", "yyy")); - - AsmAnnotationUtils.addAnnotationInfo(classNodeA.visibleAnnotations, Type.getDescriptor(AdviceInfo.class), - "adviceInfos", "fff"); - - Assertions - .assertThat(AsmAnnotationUtils.queryAnnotationInfo(classNodeA.visibleAnnotations, - Type.getDescriptor(AdviceInfo.class), "adviceInfos")) - .isEqualTo(Arrays.asList("xxxx", "yyy", "fff")); - - Assertions.assertThat(AsmAnnotationUtils.queryAnnotationInfo(classNodeB.visibleAnnotations, - Type.getDescriptor(AdviceInfo.class), "adviceInfos")).isEmpty(); - - AsmAnnotationUtils.addAnnotationInfo(classNodeB.visibleAnnotations, Type.getDescriptor(AdviceInfo.class), - "adviceInfos", "fff"); - - Assertions.assertThat(AsmAnnotationUtils.queryAnnotationInfo(classNodeB.visibleAnnotations, - Type.getDescriptor(AdviceInfo.class), "adviceInfos")).isEqualTo(Arrays.asList("fff")); - - } - -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/AsmUtilsTest.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/AsmUtilsTest.java deleted file mode 100644 index 21c122b16..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/AsmUtilsTest.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -import java.io.IOException; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.junit.Test; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassWriter; -import com.alibaba.arthas.deps.org.objectweb.asm.MethodVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.VerifyUtils; - -public class AsmUtilsTest { - - abstract static class TestClass { - public static synchronized List sss(int i, long l, List list) throws IOException, ArrayIndexOutOfBoundsException { - return null; - } - protected abstract String hello(String ss); - } - - static class TestConstructorClass { - public TestConstructorClass(int i, String s) { - - } - } - - @Test - public void testMethodDeclaration() throws IOException { - ClassNode classNode = AsmUtils.loadClass(TestClass.class); - MethodNode sss = AsmUtils.findFirstMethod(classNode.methods, "sss"); - - MethodNode hello = AsmUtils.findFirstMethod(classNode.methods, "hello"); - - MethodNode constructor = AsmUtils.findFirstMethod(AsmUtils.loadClass(TestConstructorClass.class).methods, ""); - - String helloDeclaration = AsmUtils.methodDeclaration(Type.getType(TestClass.class), hello); - String sssDeclaration = AsmUtils.methodDeclaration(Type.getType(TestClass.class), sss); - - String constructorDeclaration = AsmUtils.methodDeclaration(Type.getType(TestConstructorClass.class), constructor); - - System.err.println(helloDeclaration); - System.err.println(sssDeclaration); - System.err.println(constructorDeclaration); - - Assertions.assertThat(helloDeclaration).isEqualTo("protected abstract java.lang.String hello(java.lang.String)"); - Assertions.assertThat(sssDeclaration).isEqualTo( - "public static synchronized java.util.List sss(int, long, java.util.List) throws java.io.IOException, java.lang.ArrayIndexOutOfBoundsException"); - Assertions.assertThat(constructorDeclaration).isEqualTo("public com.taobao.arthas.bytekit.utils.AsmUtilsTest$TestConstructorClass(int, java.lang.String)"); - } - - public static byte[] emptyMethodBytes() throws Exception { - ClassWriter cw = new ClassWriter(0); - MethodVisitor mv; - - cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "LEmptyClass", null, "java/lang/Object", null); - - { - mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "", "()V", null, null); - mv.visitCode(); - mv.visitVarInsn(Opcodes.ALOAD, 0); - mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "", "()V", false); - mv.visitInsn(Opcodes.RETURN); - mv.visitMaxs(1, 1); - mv.visitEnd(); - } - { - mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "emptyMethod", "()V", null, null); - // mv.visitCode(); - mv.visitInsn(Opcodes.RETURN); - // mv.visitMaxs(0, 0); - // mv.visitEnd(); - } - cw.visitEnd(); - - return cw.toByteArray(); - } - - @Test - public void emptyMethodTest() throws Exception { - - byte[] emptyMethodBytes = emptyMethodBytes(); - - VerifyUtils.asmVerify(emptyMethodBytes); - VerifyUtils.instanceVerity(emptyMethodBytes); - - ClassNode classNode = AsmUtils.toClassNode(emptyMethodBytes); - MethodNode methodNode = AsmUtils.findFirstMethod(classNode.methods, "emptyMethod"); - - AbstractInsnNode first = methodNode.instructions.getFirst(); - AbstractInsnNode last = methodNode.instructions.getLast(); - System.err.println(first); - System.err.println(last); - - int size = methodNode.instructions.size(); - for (int i = 0; i < size; ++i) { - System.err.println(methodNode.instructions.get(i)); - } - - // String asmCode = AsmUtils.toASMCode(classNode); - // System.err.println(asmCode); - } - - private String aaa = ""; - public void xxx () { - aaa = "bbb"; - } - - @Test - public void testFieldAccess() throws IOException { - ClassNode classNode = AsmUtils.loadClass(AsmUtilsTest.class); - - MethodNode methodNode = AsmUtils.findFirstMethod(classNode.methods, "xxx"); - - int size = methodNode.instructions.size(); - for (int i = 0; i < size; ++i) { - System.err.println(methodNode.instructions.get(i)); - } - - - } - - - @Test - public void testRenameClass() throws Exception { - ClassNode classNode = AsmUtils.loadClass(AsmUtilsTest.class); - - byte[] classBytes = AsmUtils.toBytes(classNode); - - byte[] renameClass = AsmUtils.renameClass(classBytes, "com.test.Test.XXX"); - - VerifyUtils.asmVerify(renameClass); - Object object = VerifyUtils.instanceVerity(renameClass); - - Assertions.assertThat(object.getClass().getName()).isEqualTo("com.test.Test.XXX"); - } - - @Test - public void testGetMajorVersion() throws Exception { - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_1)).isEqualTo(45); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_2)).isEqualTo(46); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_3)).isEqualTo(47); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_4)).isEqualTo(48); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_5)).isEqualTo(49); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_6)).isEqualTo(50); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_7)).isEqualTo(51); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V1_8)).isEqualTo(52); - - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V9)).isEqualTo(53); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V10)).isEqualTo(54); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V11)).isEqualTo(55); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V12)).isEqualTo(56); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V13)).isEqualTo(57); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V14)).isEqualTo(58); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V15)).isEqualTo(59); - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V16)).isEqualTo(60); - - Assertions.assertThat(AsmUtils.getMajorVersion(Opcodes.V16 | Opcodes.V_PREVIEW)).isEqualTo(60); - } - - @Test - public void testSetMajorVersion() throws Exception { - int version = Opcodes.V16 | Opcodes.V_PREVIEW; - int newVersion = AsmUtils.setMajorVersion(version, 58); - - AsmUtils.getMajorVersion(newVersion); - - Assertions.assertThat(AsmUtils.getMajorVersion(newVersion)).isEqualTo(58); - } -} diff --git a/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/EmptyClass.java b/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/EmptyClass.java deleted file mode 100644 index 4e5399ae4..000000000 --- a/bytekit/src/test/java/com/taobao/arthas/bytekit/utils/EmptyClass.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.taobao.arthas.bytekit.utils; - -public class EmptyClass { - - public static void emptyMethod() { - - } - -} diff --git a/client/pom.xml b/client/pom.xml index 68e48d1e0..04366fc6e 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -1,9 +1,9 @@ - + arthas-all com.taobao.arthas - 3.4.4-SNAPSHOT + ${revision} ../pom.xml 4.0.0 diff --git a/common/pom.xml b/common/pom.xml index d4fbe9152..3fe76c607 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-common diff --git a/common/src/main/java/com/taobao/arthas/common/ArthasConstants.java b/common/src/main/java/com/taobao/arthas/common/ArthasConstants.java index 2b0fc144f..abed4cf58 100644 --- a/common/src/main/java/com/taobao/arthas/common/ArthasConstants.java +++ b/common/src/main/java/com/taobao/arthas/common/ArthasConstants.java @@ -13,4 +13,29 @@ public class ArthasConstants { * @see io.netty.channel.local.LocalChannel */ public static final String NETTY_LOCAL_ADDRESS = "arthas-netty-LocalAddress"; + + public static final int MAX_HTTP_CONTENT_LENGTH = 1024 * 1024 * 8; + + public static final String ARTHAS_OUTPUT = "arthas-output"; + + public static final String APP_NAME = "app-name"; + + public static final String PROJECT_NAME = "project.name"; + public static final String SPRING_APPLICATION_NAME = "spring.application.name"; + + public static final int TELNET_PORT = 3658; + + public static final String DEFAULT_WEBSOCKET_PATH = "/ws"; + public static final int WEBSOCKET_IDLE_SECONDS = 60; + + /** + * HTTP cookie id + */ + public static final String ASESSION_KEY = "asession"; + + public static final String DEFAULT_USERNAME = "arthas"; + public static final String SUBJECT_KEY = "subject"; + public static final String AUTH = "auth"; + public static final String USERNAME_KEY = "username"; + public static final String PASSWORD_KEY = "password"; } diff --git a/common/src/main/java/com/taobao/arthas/common/IOUtils.java b/common/src/main/java/com/taobao/arthas/common/IOUtils.java index 860f04d93..a276289b7 100644 --- a/common/src/main/java/com/taobao/arthas/common/IOUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/IOUtils.java @@ -94,6 +94,14 @@ public class IOUtils { return null; } + public static boolean isSubFile(File parent, File child) throws IOException { + return child.getCanonicalPath().startsWith(parent.getCanonicalPath() + File.separator); + } + + public static boolean isSubFile(String parent, String child) throws IOException { + return isSubFile(new File(parent), new File(child)); + } + public static void unzip(String zipFile, String extractFolder) throws IOException { File file = new File(zipFile); ZipFile zip = null; @@ -101,9 +109,9 @@ public class IOUtils { int BUFFER = 1024 * 8; zip = new ZipFile(file); - String newPath = extractFolder; + File newPath = new File(extractFolder); + newPath.mkdirs(); - new File(newPath).mkdir(); Enumeration zipFileEntries = zip.entries(); // Process each entry @@ -113,6 +121,10 @@ public class IOUtils { String currentEntry = entry.getName(); File destFile = new File(newPath, currentEntry); + if (!isSubFile(newPath, destFile)) { + throw new IOException("Bad zip entry: " + currentEntry); + } + // destFile = new File(newPath, destFile.getName()); File destinationParent = destFile.getParentFile(); diff --git a/common/src/main/java/com/taobao/arthas/common/JavaVersionUtils.java b/common/src/main/java/com/taobao/arthas/common/JavaVersionUtils.java index 6f25861de..603b18994 100644 --- a/common/src/main/java/com/taobao/arthas/common/JavaVersionUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/JavaVersionUtils.java @@ -54,4 +54,8 @@ public class JavaVersionUtils { public static boolean isGreaterThanJava8() { return JAVA_VERSION > 1.8f; } + + public static boolean isGreaterThanJava11() { + return JAVA_VERSION > 11.0f; + } } diff --git a/common/src/main/java/com/taobao/arthas/common/OSUtils.java b/common/src/main/java/com/taobao/arthas/common/OSUtils.java index 7c831e018..d167377a4 100644 --- a/common/src/main/java/com/taobao/arthas/common/OSUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/OSUtils.java @@ -59,10 +59,14 @@ public class OSUtils { return arch; } - public static boolean isArm() { + public static boolean isArm32() { return "arm_32".equals(arch); } + public static boolean isArm64() { + return "aarch_64".equals(arch); + } + private static String normalizeArch(String value) { value = normalize(value); if (value.matches("^(x8664|amd64|ia32e|em64t|x64)$")) { diff --git a/common/src/main/java/com/taobao/arthas/common/Pair.java b/common/src/main/java/com/taobao/arthas/common/Pair.java new file mode 100644 index 000000000..bbebf836c --- /dev/null +++ b/common/src/main/java/com/taobao/arthas/common/Pair.java @@ -0,0 +1,64 @@ +package com.taobao.arthas.common; + +public class Pair { + private final X x; + private final Y y; + + public Pair(X x, Y y) { + this.x = x; + this.y = y; + } + + public X getFirst() { + return x; + } + + public Y getSecond() { + return y; + } + + public static Pair make(A a, B b) { + return new Pair(a, b); + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Pair)) + return false; + + Pair other = (Pair) o; + + if (x == null) { + if (other.x != null) + return false; + } else { + if (!x.equals(other.x)) + return false; + } + if (y == null) { + if (other.y != null) + return false; + } else { + if (!y.equals(other.y)) + return false; + } + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + if (x != null) + hashCode = x.hashCode(); + if (y != null) + hashCode = (hashCode * 31) + y.hashCode(); + return hashCode; + } + + @Override + public String toString() { + return "P[" + x + "," + y + "]"; + } +} diff --git a/common/src/main/java/com/taobao/arthas/common/PidUtils.java b/common/src/main/java/com/taobao/arthas/common/PidUtils.java index 3dd74555a..f13facd71 100644 --- a/common/src/main/java/com/taobao/arthas/common/PidUtils.java +++ b/common/src/main/java/com/taobao/arthas/common/PidUtils.java @@ -1,6 +1,7 @@ package com.taobao.arthas.common; import java.lang.management.ManagementFactory; +import java.util.Map; /** * @@ -11,19 +12,31 @@ public class PidUtils { private static String PID = "-1"; private static long pid = -1; + private static String MAIN_CLASS = ""; + static { // https://stackoverflow.com/a/7690178 - String jvmName = ManagementFactory.getRuntimeMXBean().getName(); - int index = jvmName.indexOf('@'); + try { + String jvmName = ManagementFactory.getRuntimeMXBean().getName(); + int index = jvmName.indexOf('@'); - if (index > 0) { - try { + if (index > 0) { PID = Long.toString(Long.parseLong(jvmName.substring(0, index))); pid = Long.parseLong(PID); - } catch (Throwable e) { - // ignore } + } catch (Throwable e) { + // ignore + } + + try { + for (final Map.Entry entry : System.getenv().entrySet()) { + if (entry.getKey().startsWith("JAVA_MAIN_CLASS")) // like JAVA_MAIN_CLASS_13328 + MAIN_CLASS = entry.getValue(); + } + } catch (Throwable e) { + // ignore } + } private PidUtils() { @@ -36,4 +49,8 @@ public class PidUtils { public static long currentLongPid() { return pid; } + + public static String mainClass() { + return MAIN_CLASS; + } } diff --git a/common/src/main/java/com/taobao/arthas/common/VmToolUtils.java b/common/src/main/java/com/taobao/arthas/common/VmToolUtils.java new file mode 100644 index 000000000..7967b415e --- /dev/null +++ b/common/src/main/java/com/taobao/arthas/common/VmToolUtils.java @@ -0,0 +1,30 @@ +package com.taobao.arthas.common; + +/** + * + * @author hengyunabc 2021-04-27 + * + */ +public class VmToolUtils { + private static String libName = null; + static { + if (OSUtils.isMac()) { + libName = "libArthasJniLibrary-x64.dylib"; + } + if (OSUtils.isLinux()) { + libName = "libArthasJniLibrary-x64.so"; + if (OSUtils.isArm32()) { + libName = "libArthasJniLibrary-arm.so"; + } else if (OSUtils.isArm64()) { + libName = "libArthasJniLibrary-aarch64.so"; + } + } + if (OSUtils.isWindows()) { + libName = "libArthasJniLibrary-x64.dll"; + } + } + + public static String detectLibName() { + return libName; + } +} diff --git a/core/pom.xml b/core/pom.xml index 5d809cf05..f3119e240 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-core @@ -122,9 +122,14 @@ com.taobao.arthas - arthas-bytekit + arthas-vmtool ${project.version} + + com.alibaba + bytekit-core + + net.bytebuddy byte-buddy-agent @@ -225,7 +230,7 @@ com.taobao.arthas - arthas-demo + math-game ${project.version} test @@ -235,6 +240,14 @@ test + + org.jboss.modules + jboss-modules + 1.11.0.Final + test + true + + org.benf cfr diff --git a/core/src/main/java/arthas.properties b/core/src/main/java/arthas.properties index 8a906de63..e562eea80 100644 --- a/core/src/main/java/arthas.properties +++ b/core/src/main/java/arthas.properties @@ -1,7 +1,21 @@ #arthas.config.overrideAll=true arthas.telnetPort=3658 arthas.httpPort=8563 -arthas.ip=localhost +arthas.ip=127.0.0.1 +# seconds +arthas.sessionTimeout=1800 + +#arthas.enhanceLoaders=java.lang.ClassLoader + +# https://arthas.aliyun.com/doc/en/auth +# arthas.username=arthas +# arthas.password=arthas + +#arthas.appName=demoapp #arthas.tunnelServer=ws://127.0.0.1:7777/ws #arthas.agentId=mmmmmmyiddddd + +#arthas.disabledCommands=stop,dump + +#arthas.outputPath=arthas-output \ No newline at end of file diff --git a/core/src/main/java/com/taobao/arthas/core/Arthas.java b/core/src/main/java/com/taobao/arthas/core/Arthas.java index 901e3f364..c3375e6f8 100644 --- a/core/src/main/java/com/taobao/arthas/core/Arthas.java +++ b/core/src/main/java/com/taobao/arthas/core/Arthas.java @@ -3,6 +3,7 @@ package com.taobao.arthas.core; import com.sun.tools.attach.VirtualMachine; import com.sun.tools.attach.VirtualMachineDescriptor; import com.taobao.arthas.common.AnsiLog; +import com.taobao.arthas.common.ArthasConstants; import com.taobao.arthas.common.JavaVersionUtils; import com.taobao.arthas.core.config.Configure; import com.taobao.middleware.cli.CLI; @@ -21,9 +22,6 @@ import java.util.Properties; */ public class Arthas { - private static final String DEFAULT_TELNET_PORT = "3658"; - private static final String DEFAULT_HTTP_PORT = "8563"; - private Arthas(String[] args) throws Exception { attachAgent(parse(args)); } @@ -34,38 +32,55 @@ public class Arthas { Option agent = new TypedOption().setType(String.class).setShortName("agent").setRequired(true); Option target = new TypedOption().setType(String.class).setShortName("target-ip"); Option telnetPort = new TypedOption().setType(Integer.class) - .setShortName("telnet-port").setDefaultValue(DEFAULT_TELNET_PORT); + .setShortName("telnet-port"); Option httpPort = new TypedOption().setType(Integer.class) - .setShortName("http-port").setDefaultValue(DEFAULT_HTTP_PORT); + .setShortName("http-port"); Option sessionTimeout = new TypedOption().setType(Integer.class) - .setShortName("session-timeout").setDefaultValue("" + Configure.DEFAULT_SESSION_TIMEOUT_SECONDS); + .setShortName("session-timeout"); + + Option username = new TypedOption().setType(String.class).setShortName("username"); + Option password = new TypedOption().setType(String.class).setShortName("password"); Option tunnelServer = new TypedOption().setType(String.class).setShortName("tunnel-server"); Option agentId = new TypedOption().setType(String.class).setShortName("agent-id"); + Option appName = new TypedOption().setType(String.class).setShortName(ArthasConstants.APP_NAME); Option statUrl = new TypedOption().setType(String.class).setShortName("stat-url"); + Option disabledCommands = new TypedOption().setType(String.class).setShortName("disabled-commands"); CLI cli = CLIs.create("arthas").addOption(pid).addOption(core).addOption(agent).addOption(target) - .addOption(telnetPort).addOption(httpPort).addOption(sessionTimeout).addOption(tunnelServer).addOption(agentId).addOption(statUrl); + .addOption(telnetPort).addOption(httpPort).addOption(sessionTimeout) + .addOption(username).addOption(password) + .addOption(tunnelServer).addOption(agentId).addOption(appName).addOption(statUrl).addOption(disabledCommands); CommandLine commandLine = cli.parse(Arrays.asList(args)); Configure configure = new Configure(); configure.setJavaPid((Long) commandLine.getOptionValue("pid")); configure.setArthasAgent((String) commandLine.getOptionValue("agent")); configure.setArthasCore((String) commandLine.getOptionValue("core")); - configure.setSessionTimeout((Integer)commandLine.getOptionValue("session-timeout")); - if (commandLine.getOptionValue("target-ip") == null) { - throw new IllegalStateException("as.sh is too old to support web console, " + - "please run the following command to upgrade to latest version:" + - "\ncurl -sLk https://arthas.aliyun.com/install.sh | sh"); + if (commandLine.getOptionValue("session-timeout") != null) { + configure.setSessionTimeout((Integer) commandLine.getOptionValue("session-timeout")); + } + + if (commandLine.getOptionValue("target-ip") != null) { + configure.setIp((String) commandLine.getOptionValue("target-ip")); } - configure.setIp((String) commandLine.getOptionValue("target-ip")); - configure.setTelnetPort((Integer) commandLine.getOptionValue("telnet-port")); - configure.setHttpPort((Integer) commandLine.getOptionValue("http-port")); + + if (commandLine.getOptionValue("telnet-port") != null) { + configure.setTelnetPort((Integer) commandLine.getOptionValue("telnet-port")); + } + if (commandLine.getOptionValue("http-port") != null) { + configure.setHttpPort((Integer) commandLine.getOptionValue("http-port")); + } + + configure.setUsername((String) commandLine.getOptionValue("username")); + configure.setPassword((String) commandLine.getOptionValue("password")); configure.setTunnelServer((String) commandLine.getOptionValue("tunnel-server")); configure.setAgentId((String) commandLine.getOptionValue("agent-id")); configure.setStatUrl((String) commandLine.getOptionValue("stat-url")); + configure.setDisabledCommands((String) commandLine.getOptionValue("disabled-commands")); + configure.setAppName((String) commandLine.getOptionValue(ArthasConstants.APP_NAME)); return configure; } diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/AccessPoint.java b/core/src/main/java/com/taobao/arthas/core/advisor/AccessPoint.java new file mode 100644 index 000000000..1d361c4ed --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/advisor/AccessPoint.java @@ -0,0 +1,22 @@ +package com.taobao.arthas.core.advisor; + +public enum AccessPoint { + ACCESS_BEFORE(1, "AtEnter"), ACCESS_AFTER_RETUNING(1 << 1, "AtExit"), ACCESS_AFTER_THROWING(1 << 2, "AtExceptionExit"); + + private int value; + + private String key; + + public int getValue() { + return value; + } + + public String getKey() { + return key; + } + + AccessPoint(int value, String key) { + this.value = value; + this.key = key; + } +} \ No newline at end of file diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/Advice.java b/core/src/main/java/com/taobao/arthas/core/advisor/Advice.java index 55cca86c3..685454cad 100644 --- a/core/src/main/java/com/taobao/arthas/core/advisor/Advice.java +++ b/core/src/main/java/com/taobao/arthas/core/advisor/Advice.java @@ -12,11 +12,6 @@ public class Advice { private final Object[] params; private final Object returnObj; private final Throwable throwExp; - - private final static int ACCESS_BEFORE = 1; - private final static int ACCESS_AFTER_RETUNING = 1 << 1; - private final static int ACCESS_AFTER_THROWING = 1 << 2; - private final boolean isBefore; private final boolean isThrow; private final boolean isReturn; @@ -64,14 +59,14 @@ public class Advice { /** * for finish * - * @param loader 类加载器 - * @param clazz 类 - * @param method 方法 - * @param target 目标类 - * @param params 调用参数 + * @param loader 类加载器 + * @param clazz 类 + * @param method 方法 + * @param target 目标类 + * @param params 调用参数 * @param returnObj 返回值 - * @param throwExp 抛出异常 - * @param access 进入场景 + * @param throwExp 抛出异常 + * @param access 进入场景 */ private Advice( ClassLoader loader, @@ -89,16 +84,16 @@ public class Advice { this.params = params; this.returnObj = returnObj; this.throwExp = throwExp; - isBefore = (access & ACCESS_BEFORE) == ACCESS_BEFORE; - isThrow = (access & ACCESS_AFTER_THROWING) == ACCESS_AFTER_THROWING; - isReturn = (access & ACCESS_AFTER_RETUNING) == ACCESS_AFTER_RETUNING; + isBefore = (access & AccessPoint.ACCESS_BEFORE.getValue()) == AccessPoint.ACCESS_BEFORE.getValue(); + isThrow = (access & AccessPoint.ACCESS_AFTER_THROWING.getValue()) == AccessPoint.ACCESS_AFTER_THROWING.getValue(); + isReturn = (access & AccessPoint.ACCESS_AFTER_RETUNING.getValue()) == AccessPoint.ACCESS_AFTER_RETUNING.getValue(); } public static Advice newForBefore(ClassLoader loader, - Class clazz, - ArthasMethod method, - Object target, - Object[] params) { + Class clazz, + ArthasMethod method, + Object target, + Object[] params) { return new Advice( loader, clazz, @@ -107,16 +102,16 @@ public class Advice { params, null, //returnObj null, //throwExp - ACCESS_BEFORE + AccessPoint.ACCESS_BEFORE.getValue() ); } public static Advice newForAfterRetuning(ClassLoader loader, - Class clazz, - ArthasMethod method, - Object target, - Object[] params, - Object returnObj) { + Class clazz, + ArthasMethod method, + Object target, + Object[] params, + Object returnObj) { return new Advice( loader, clazz, @@ -125,16 +120,16 @@ public class Advice { params, returnObj, null, //throwExp - ACCESS_AFTER_RETUNING + AccessPoint.ACCESS_AFTER_RETUNING.getValue() ); } public static Advice newForAfterThrowing(ClassLoader loader, - Class clazz, - ArthasMethod method, - Object target, - Object[] params, - Throwable throwExp) { + Class clazz, + ArthasMethod method, + Object target, + Object[] params, + Throwable throwExp) { return new Advice( loader, clazz, @@ -143,8 +138,9 @@ public class Advice { params, null, //returnObj throwExp, - ACCESS_AFTER_THROWING + AccessPoint.ACCESS_AFTER_THROWING.getValue() ); + } } diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/AdviceListenerManager.java b/core/src/main/java/com/taobao/arthas/core/advisor/AdviceListenerManager.java index ab710776d..f78b2a870 100644 --- a/core/src/main/java/com/taobao/arthas/core/advisor/AdviceListenerManager.java +++ b/core/src/main/java/com/taobao/arthas/core/advisor/AdviceListenerManager.java @@ -100,7 +100,7 @@ public class AdviceListenerManager { }, 3, 3, TimeUnit.SECONDS); } - static private ConcurrentWeakKeyHashMap adviceListenerMap = new ConcurrentWeakKeyHashMap(); + private static final ConcurrentWeakKeyHashMap adviceListenerMap = new ConcurrentWeakKeyHashMap(); static class ClassLoaderAdviceListenerManager { private ConcurrentHashMap> map = new ConcurrentHashMap>(); diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/ArthasMethod.java b/core/src/main/java/com/taobao/arthas/core/advisor/ArthasMethod.java index 0672c11d6..6d102a64b 100644 --- a/core/src/main/java/com/taobao/arthas/core/advisor/ArthasMethod.java +++ b/core/src/main/java/com/taobao/arthas/core/advisor/ArthasMethod.java @@ -4,7 +4,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; +import com.alibaba.deps.org.objectweb.asm.Type; import com.taobao.arthas.core.util.StringUtils; /** @@ -92,7 +92,6 @@ public class ArthasMethod { if ("".equals(this.methodName)) { this.constructor = clazz.getDeclaredConstructor(argsClasses); - ; } else { this.method = clazz.getDeclaredMethod(methodName, argsClasses); } diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/CodeLock.java b/core/src/main/java/com/taobao/arthas/core/advisor/CodeLock.java deleted file mode 100644 index 1095b775e..000000000 --- a/core/src/main/java/com/taobao/arthas/core/advisor/CodeLock.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.taobao.arthas.core.advisor; - -/** - * 代码锁
- * 什么叫代码锁?代码锁的出现是由于在字节码中,我们无法用简单的if语句来判定这段代码是生成的还是原有的。 - * 这会导致一些监控逻辑的混乱,比如trace命令如果不使用代码锁保护,将能看到Arthas所植入的代码并进行跟踪 - * Created by vlinux on 15/5/28. - */ -public interface CodeLock { - - /** - * 根据字节码流锁或解锁代码
- * 通过对字节码流的判断,决定当前代码是锁定和解锁 - * - * @param opcode 字节码 - */ - void code(int opcode); - - /** - * 判断当前代码是否还在锁定中 - * - * @return true/false - */ - boolean isLock(); - - /** - * 将一个代码块纳入代码锁保护范围 - * - * @param block 代码块 - */ - void lock(Block block); - - /** - * 代码块 - */ - interface Block { - /** - * 代码 - */ - void code(); - } - -} diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/Enhancer.java b/core/src/main/java/com/taobao/arthas/core/advisor/Enhancer.java index 6704ebf27..4cd05774d 100644 --- a/core/src/main/java/com/taobao/arthas/core/advisor/Enhancer.java +++ b/core/src/main/java/com/taobao/arthas/core/advisor/Enhancer.java @@ -21,27 +21,27 @@ import java.util.Map; import java.util.Set; import java.util.WeakHashMap; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassReader; -import com.alibaba.arthas.deps.org.objectweb.asm.Opcodes; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.AbstractInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodInsnNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; +import com.alibaba.deps.org.objectweb.asm.ClassReader; +import com.alibaba.deps.org.objectweb.asm.Opcodes; +import com.alibaba.deps.org.objectweb.asm.Type; +import com.alibaba.deps.org.objectweb.asm.tree.AbstractInsnNode; +import com.alibaba.deps.org.objectweb.asm.tree.ClassNode; +import com.alibaba.deps.org.objectweb.asm.tree.MethodInsnNode; +import com.alibaba.deps.org.objectweb.asm.tree.MethodNode; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.asm.location.Location; -import com.taobao.arthas.bytekit.asm.location.LocationType; -import com.taobao.arthas.bytekit.asm.location.MethodInsnNodeWare; -import com.taobao.arthas.bytekit.asm.location.filter.GroupLocationFilter; -import com.taobao.arthas.bytekit.asm.location.filter.InvokeCheckLocationFilter; -import com.taobao.arthas.bytekit.asm.location.filter.InvokeContainLocationFilter; -import com.taobao.arthas.bytekit.asm.location.filter.LocationFilter; -import com.taobao.arthas.bytekit.utils.AsmOpUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; +import com.alibaba.bytekit.asm.MethodProcessor; +import com.alibaba.bytekit.asm.interceptor.InterceptorProcessor; +import com.alibaba.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; +import com.alibaba.bytekit.asm.location.Location; +import com.alibaba.bytekit.asm.location.LocationType; +import com.alibaba.bytekit.asm.location.MethodInsnNodeWare; +import com.alibaba.bytekit.asm.location.filter.GroupLocationFilter; +import com.alibaba.bytekit.asm.location.filter.InvokeCheckLocationFilter; +import com.alibaba.bytekit.asm.location.filter.InvokeContainLocationFilter; +import com.alibaba.bytekit.asm.location.filter.LocationFilter; +import com.alibaba.bytekit.utils.AsmOpUtils; +import com.alibaba.bytekit.utils.AsmUtils; import com.taobao.arthas.core.GlobalOptions; import com.taobao.arthas.core.advisor.SpyInterceptors.SpyInterceptor1; import com.taobao.arthas.core.advisor.SpyInterceptors.SpyInterceptor2; @@ -72,6 +72,7 @@ public class Enhancer implements ClassFileTransformer { private final boolean isTracing; private final boolean skipJDKTrace; private final Matcher classNameMatcher; + private final Matcher classNameExcludeMatcher; private final Matcher methodNameMatcher; private final EnhancerAffect affect; private Set> matchingClasses = null; @@ -93,11 +94,13 @@ public class Enhancer implements ClassFileTransformer { * @param affect 影响统计 */ public Enhancer(AdviceListener listener, boolean isTracing, boolean skipJDKTrace, Matcher classNameMatcher, + Matcher classNameExcludeMatcher, Matcher methodNameMatcher) { this.listener = listener; this.isTracing = isTracing; this.skipJDKTrace = skipJDKTrace; this.classNameMatcher = classNameMatcher; + this.classNameExcludeMatcher = classNameExcludeMatcher; this.methodNameMatcher = methodNameMatcher; this.affect = new EnhancerAffect(); affect.setListenerId(listener.id()); @@ -114,7 +117,7 @@ public class Enhancer implements ClassFileTransformer { } } catch (Throwable e) { logger.error("the classloader can not load SpyAPI, ignore it. classloader: {}, className: {}", - inClassLoader.getClass().getName(), className); + inClassLoader.getClass().getName(), className, e); return null; } @@ -158,6 +161,15 @@ public class Enhancer implements ClassFileTransformer { } } + // https://github.com/alibaba/arthas/issues/1690 + if (AsmUtils.isEnhancerByCGLIB(className)) { + for (MethodNode methodNode : matchedMethods) { + if (AsmUtils.isConstructor(methodNode)) { + AsmUtils.fixConstructorExceptionTable(methodNode); + } + } + } + // 用于检查是否已插入了 spy函数,如果已有则不重复处理 GroupLocationFilter groupLocationFilter = new GroupLocationFilter(); @@ -183,6 +195,11 @@ public class Enhancer implements ClassFileTransformer { groupLocationFilter.addFilter(invokeExceptionFilter); for (MethodNode methodNode : matchedMethods) { + if (AsmUtils.isNative(methodNode)) { + logger.info("ignore native method: {}", + AsmUtils.methodDeclaration(Type.getObjectType(classNode.name), methodNode)); + continue; + } // 先查找是否有 atBeforeInvoke 函数,如果有,则说明已经有trace了,则直接不再尝试增强,直接插入 listener if(AsmUtils.containsMethodInsnNode(methodNode, Type.getInternalName(SpyAPI.class), "atBeforeInvoke")) { for (AbstractInsnNode insnNode = methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode @@ -303,16 +320,23 @@ public class Enhancer implements ClassFileTransformer { * * @param classes 类集合 */ - private static void filter(Set> classes) { + private void filter(Set> classes) { final Iterator> it = classes.iterator(); while (it.hasNext()) { final Class clazz = it.next(); - if (null == clazz || isSelf(clazz) || isUnsafeClass(clazz) || isUnsupportedClass(clazz)) { + if (null == clazz || isSelf(clazz) || isUnsafeClass(clazz) || isUnsupportedClass(clazz) || isExclude(clazz)) { it.remove(); } } } + private boolean isExclude(Class clazz) { + if (this.classNameExcludeMatcher != null) { + return classNameExcludeMatcher.matching(clazz.getName()); + } + return false; + } + /** * 是否过滤Arthas加载的类 */ @@ -418,16 +442,8 @@ public class Enhancer implements ClassFileTransformer { } } - final ClassFileTransformer resetClassFileTransformer = new ClassFileTransformer() { - @Override - public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, - ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { - return null; - } - }; - try { - enhance(inst, resetClassFileTransformer, enhanceClassSet); + enhance(inst, enhanceClassSet); logger.info("Success to reset classes: " + enhanceClassSet); } finally { for (Class resetClass : enhanceClassSet) { @@ -440,18 +456,13 @@ public class Enhancer implements ClassFileTransformer { } // 批量增强 - private static void enhance(Instrumentation inst, ClassFileTransformer transformer, Set> classes) + private static void enhance(Instrumentation inst, Set> classes) throws UnmodifiableClassException { - try { - inst.addTransformer(transformer, true); - int size = classes.size(); - Class[] classArray = new Class[size]; - arraycopy(classes.toArray(), 0, classArray, 0, size); - if (classArray.length > 0) { - inst.retransformClasses(classArray); - } - } finally { - inst.removeTransformer(transformer); + int size = classes.size(); + Class[] classArray = new Class[size]; + arraycopy(classes.toArray(), 0, classArray, 0, size); + if (classArray.length > 0) { + inst.retransformClasses(classArray); } } } diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/SpyImpl.java b/core/src/main/java/com/taobao/arthas/core/advisor/SpyImpl.java index 4e4a339af..8cf549623 100644 --- a/core/src/main/java/com/taobao/arthas/core/advisor/SpyImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/advisor/SpyImpl.java @@ -2,12 +2,12 @@ package com.taobao.arthas.core.advisor; import java.arthas.SpyAPI.AbstractSpy; import java.util.List; -import java.util.regex.Pattern; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; import com.taobao.arthas.core.shell.system.ExecStatus; import com.taobao.arthas.core.shell.system.ProcessAware; +import com.taobao.arthas.core.util.StringUtils; /** *

@@ -27,7 +27,7 @@ public class SpyImpl extends AbstractSpy {
     public void atEnter(Class clazz, String methodInfo, Object target, Object[] args) {
         ClassLoader classLoader = clazz.getClassLoader();
 
-        String[] info = splitMethodInfo(methodInfo);
+        String[] info = StringUtils.splitMethodInfo(methodInfo);
         String methodName = info[0];
         String methodDesc = info[1];
         // TODO listener 只用查一次,放到 thread local里保存起来就可以了!
@@ -52,7 +52,7 @@ public class SpyImpl extends AbstractSpy {
     public void atExit(Class clazz, String methodInfo, Object target, Object[] args, Object returnObject) {
         ClassLoader classLoader = clazz.getClassLoader();
 
-        String[] info = splitMethodInfo(methodInfo);
+        String[] info = StringUtils.splitMethodInfo(methodInfo);
         String methodName = info[0];
         String methodDesc = info[1];
 
@@ -76,7 +76,7 @@ public class SpyImpl extends AbstractSpy {
     public void atExceptionExit(Class clazz, String methodInfo, Object target, Object[] args, Throwable throwable) {
         ClassLoader classLoader = clazz.getClassLoader();
 
-        String[] info = splitMethodInfo(methodInfo);
+        String[] info = StringUtils.splitMethodInfo(methodInfo);
         String methodName = info[0];
         String methodDesc = info[1];
 
@@ -99,7 +99,7 @@ public class SpyImpl extends AbstractSpy {
     @Override
     public void atBeforeInvoke(Class clazz, String invokeInfo, Object target) {
         ClassLoader classLoader = clazz.getClassLoader();
-        String[] info = splitInvokeInfo(invokeInfo);
+        String[] info = StringUtils.splitInvokeInfo(invokeInfo);
         String owner = info[0];
         String methodName = info[1];
         String methodDesc = info[2];
@@ -125,7 +125,7 @@ public class SpyImpl extends AbstractSpy {
     @Override
     public void atAfterInvoke(Class clazz, String invokeInfo, Object target) {
         ClassLoader classLoader = clazz.getClassLoader();
-        String[] info = splitInvokeInfo(invokeInfo);
+        String[] info = StringUtils.splitInvokeInfo(invokeInfo);
         String owner = info[0];
         String methodName = info[1];
         String methodDesc = info[2];
@@ -151,7 +151,7 @@ public class SpyImpl extends AbstractSpy {
     @Override
     public void atInvokeException(Class clazz, String invokeInfo, Object target, Throwable throwable) {
         ClassLoader classLoader = clazz.getClassLoader();
-        String[] info = splitInvokeInfo(invokeInfo);
+        String[] info = StringUtils.splitInvokeInfo(invokeInfo);
         String owner = info[0];
         String methodName = info[1];
         String methodDesc = info[2];
@@ -174,15 +174,7 @@ public class SpyImpl extends AbstractSpy {
         }
     }
 
-    private String[] splitMethodInfo(String methodInfo) {
-        return methodInfo.split(Pattern.quote("|"));
-    }
-
-    private String[] splitInvokeInfo(String invokeInfo) {
-        return invokeInfo.split(Pattern.quote("|"));
-    }
-
-    private boolean skipAdviceListener(AdviceListener adviceListener) {
+    private static boolean skipAdviceListener(AdviceListener adviceListener) {
         if (adviceListener instanceof ProcessAware) {
             ProcessAware processAware = (ProcessAware) adviceListener;
             ExecStatus status = processAware.getProcess().status();
diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/SpyInterceptors.java b/core/src/main/java/com/taobao/arthas/core/advisor/SpyInterceptors.java
index 0d73c5443..027d1044d 100644
--- a/core/src/main/java/com/taobao/arthas/core/advisor/SpyInterceptors.java
+++ b/core/src/main/java/com/taobao/arthas/core/advisor/SpyInterceptors.java
@@ -2,12 +2,12 @@ package com.taobao.arthas.core.advisor;
 
 import java.arthas.SpyAPI;
 
-import com.taobao.arthas.bytekit.asm.binding.Binding;
-import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtEnter;
-import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExceptionExit;
-import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtExit;
-import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvoke;
-import com.taobao.arthas.bytekit.asm.interceptor.annotation.AtInvokeException;
+import com.alibaba.bytekit.asm.binding.Binding;
+import com.alibaba.bytekit.asm.interceptor.annotation.AtEnter;
+import com.alibaba.bytekit.asm.interceptor.annotation.AtExceptionExit;
+import com.alibaba.bytekit.asm.interceptor.annotation.AtExit;
+import com.alibaba.bytekit.asm.interceptor.annotation.AtInvoke;
+import com.alibaba.bytekit.asm.interceptor.annotation.AtInvokeException;
 
 /**
  * 
diff --git a/core/src/main/java/com/taobao/arthas/core/advisor/TransformerManager.java b/core/src/main/java/com/taobao/arthas/core/advisor/TransformerManager.java
index 08b7fe15a..5f0947598 100644
--- a/core/src/main/java/com/taobao/arthas/core/advisor/TransformerManager.java
+++ b/core/src/main/java/com/taobao/arthas/core/advisor/TransformerManager.java
@@ -9,6 +9,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * 
+ * 
+ * * 统一管理 ClassFileTransformer
+ * * 每个增强命令对应一个 Enhancer ,也统一在这里管理
+ * 
+ * + * @see com.taobao.arthas.core.advisor.Enhancer * @author hengyunabc 2020-05-18 * */ @@ -17,6 +23,11 @@ public class TransformerManager { private Instrumentation instrumentation; private List watchTransformers = new CopyOnWriteArrayList(); private List traceTransformers = new CopyOnWriteArrayList(); + + /** + * 先于 watch/trace的 Transformer TODO 改进为全部用 order 排序? + */ + private List reTransformers = new CopyOnWriteArrayList(); private ClassFileTransformer classFileTransformer; @@ -28,6 +39,13 @@ public class TransformerManager { @Override public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { + for (ClassFileTransformer classFileTransformer : reTransformers) { + byte[] transformResult = classFileTransformer.transform(loader, className, classBeingRedefined, + protectionDomain, classfileBuffer); + if (transformResult != null) { + classfileBuffer = transformResult; + } + } for (ClassFileTransformer classFileTransformer : watchTransformers) { byte[] transformResult = classFileTransformer.transform(loader, className, classBeingRedefined, @@ -60,12 +78,18 @@ public class TransformerManager { } } + public void addRetransformer(ClassFileTransformer transformer) { + reTransformers.add(transformer); + } + public void removeTransformer(ClassFileTransformer transformer) { + reTransformers.remove(transformer); watchTransformers.remove(transformer); traceTransformers.remove(transformer); } public void destroy() { + reTransformers.clear(); watchTransformers.clear(); traceTransformers.clear(); instrumentation.removeTransformer(classFileTransformer); diff --git a/core/src/main/java/com/taobao/arthas/core/command/BuiltinCommandPack.java b/core/src/main/java/com/taobao/arthas/core/command/BuiltinCommandPack.java index 1114b9968..b2c8c2e37 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/BuiltinCommandPack.java +++ b/core/src/main/java/com/taobao/arthas/core/command/BuiltinCommandPack.java @@ -1,5 +1,10 @@ package com.taobao.arthas.core.command; +import java.util.ArrayList; +import java.util.List; + +import com.taobao.arthas.core.command.basic1000.AuthCommand; +import com.taobao.arthas.core.command.basic1000.Base64Command; import com.taobao.arthas.core.command.basic1000.CatCommand; import com.taobao.arthas.core.command.basic1000.ClsCommand; import com.taobao.arthas.core.command.basic1000.EchoCommand; @@ -11,7 +16,6 @@ import com.taobao.arthas.core.command.basic1000.OptionsCommand; import com.taobao.arthas.core.command.basic1000.PwdCommand; import com.taobao.arthas.core.command.basic1000.ResetCommand; import com.taobao.arthas.core.command.basic1000.SessionCommand; -import com.taobao.arthas.core.command.basic1000.ShutdownCommand; import com.taobao.arthas.core.command.basic1000.StopCommand; import com.taobao.arthas.core.command.basic1000.SystemEnvCommand; import com.taobao.arthas.core.command.basic1000.SystemPropertyCommand; @@ -27,6 +31,7 @@ import com.taobao.arthas.core.command.klass100.JadCommand; import com.taobao.arthas.core.command.klass100.MemoryCompilerCommand; import com.taobao.arthas.core.command.klass100.OgnlCommand; import com.taobao.arthas.core.command.klass100.RedefineCommand; +import com.taobao.arthas.core.command.klass100.RetransformCommand; import com.taobao.arthas.core.command.klass100.SearchClassCommand; import com.taobao.arthas.core.command.klass100.SearchMethodCommand; import com.taobao.arthas.core.command.logger.LoggerCommand; @@ -41,12 +46,12 @@ import com.taobao.arthas.core.command.monitor200.StackCommand; import com.taobao.arthas.core.command.monitor200.ThreadCommand; import com.taobao.arthas.core.command.monitor200.TimeTunnelCommand; import com.taobao.arthas.core.command.monitor200.TraceCommand; +import com.taobao.arthas.core.command.monitor200.VmToolCommand; import com.taobao.arthas.core.command.monitor200.WatchCommand; +import com.taobao.arthas.core.shell.command.AnnotatedCommand; import com.taobao.arthas.core.shell.command.Command; import com.taobao.arthas.core.shell.command.CommandResolver; - -import java.util.ArrayList; -import java.util.List; +import com.taobao.middleware.cli.annotations.Name; /** * TODO automatically discover the built-in commands. @@ -54,10 +59,10 @@ import java.util.List; */ public class BuiltinCommandPack implements CommandResolver { - private static List commands = new ArrayList(); + private List commands = new ArrayList(); - static { - initCommands(); + public BuiltinCommandPack(List disabledCommands) { + initCommands(disabledCommands); } @Override @@ -65,49 +70,63 @@ public class BuiltinCommandPack implements CommandResolver { return commands; } - private static void initCommands() { - commands.add(Command.create(HelpCommand.class)); - commands.add(Command.create(KeymapCommand.class)); - commands.add(Command.create(SearchClassCommand.class)); - commands.add(Command.create(SearchMethodCommand.class)); - commands.add(Command.create(ClassLoaderCommand.class)); - commands.add(Command.create(JadCommand.class)); - commands.add(Command.create(GetStaticCommand.class)); - commands.add(Command.create(MonitorCommand.class)); - commands.add(Command.create(StackCommand.class)); - commands.add(Command.create(ThreadCommand.class)); - commands.add(Command.create(TraceCommand.class)); - commands.add(Command.create(WatchCommand.class)); - commands.add(Command.create(TimeTunnelCommand.class)); - commands.add(Command.create(JvmCommand.class)); - commands.add(Command.create(PerfCounterCommand.class)); - // commands.add(Command.create(GroovyScriptCommand.class)); - commands.add(Command.create(OgnlCommand.class)); - commands.add(Command.create(MemoryCompilerCommand.class)); - commands.add(Command.create(RedefineCommand.class)); - commands.add(Command.create(DashboardCommand.class)); - commands.add(Command.create(DumpClassCommand.class)); - commands.add(Command.create(HeapDumpCommand.class)); - commands.add(Command.create(JulyCommand.class)); - commands.add(Command.create(ThanksCommand.class)); - commands.add(Command.create(OptionsCommand.class)); - commands.add(Command.create(ClsCommand.class)); - commands.add(Command.create(ResetCommand.class)); - commands.add(Command.create(VersionCommand.class)); - commands.add(Command.create(SessionCommand.class)); - commands.add(Command.create(SystemPropertyCommand.class)); - commands.add(Command.create(SystemEnvCommand.class)); - commands.add(Command.create(VMOptionCommand.class)); - commands.add(Command.create(LoggerCommand.class)); - commands.add(Command.create(HistoryCommand.class)); - commands.add(Command.create(CatCommand.class)); - commands.add(Command.create(EchoCommand.class)); - commands.add(Command.create(PwdCommand.class)); - commands.add(Command.create(MBeanCommand.class)); - commands.add(Command.create(GrepCommand.class)); - commands.add(Command.create(TeeCommand.class)); - commands.add(Command.create(ProfilerCommand.class)); - commands.add(Command.create(ShutdownCommand.class)); - commands.add(Command.create(StopCommand.class)); + private void initCommands(List disabledCommands) { + List> commandClassList = new ArrayList>(32); + commandClassList.add(HelpCommand.class); + commandClassList.add(AuthCommand.class); + commandClassList.add(KeymapCommand.class); + commandClassList.add(SearchClassCommand.class); + commandClassList.add(SearchMethodCommand.class); + commandClassList.add(ClassLoaderCommand.class); + commandClassList.add(JadCommand.class); + commandClassList.add(GetStaticCommand.class); + commandClassList.add(MonitorCommand.class); + commandClassList.add(StackCommand.class); + commandClassList.add(ThreadCommand.class); + commandClassList.add(TraceCommand.class); + commandClassList.add(WatchCommand.class); + commandClassList.add(TimeTunnelCommand.class); + commandClassList.add(JvmCommand.class); + commandClassList.add(PerfCounterCommand.class); + // commandClassList.add(GroovyScriptCommand.class); + commandClassList.add(OgnlCommand.class); + commandClassList.add(MemoryCompilerCommand.class); + commandClassList.add(RedefineCommand.class); + commandClassList.add(RetransformCommand.class); + commandClassList.add(DashboardCommand.class); + commandClassList.add(DumpClassCommand.class); + commandClassList.add(HeapDumpCommand.class); + commandClassList.add(JulyCommand.class); + commandClassList.add(ThanksCommand.class); + commandClassList.add(OptionsCommand.class); + commandClassList.add(ClsCommand.class); + commandClassList.add(ResetCommand.class); + commandClassList.add(VersionCommand.class); + commandClassList.add(SessionCommand.class); + commandClassList.add(SystemPropertyCommand.class); + commandClassList.add(SystemEnvCommand.class); + commandClassList.add(VMOptionCommand.class); + commandClassList.add(LoggerCommand.class); + commandClassList.add(HistoryCommand.class); + commandClassList.add(CatCommand.class); + commandClassList.add(Base64Command.class); + commandClassList.add(EchoCommand.class); + commandClassList.add(PwdCommand.class); + commandClassList.add(MBeanCommand.class); + commandClassList.add(GrepCommand.class); + commandClassList.add(TeeCommand.class); + commandClassList.add(ProfilerCommand.class); + commandClassList.add(VmToolCommand.class); + commandClassList.add(StopCommand.class); + + for (Class clazz : commandClassList) { + Name name = clazz.getAnnotation(Name.class); + if (name != null && name.value() != null) { + if (disabledCommands.contains(name.value())) { + continue; + } + } + commands.add(Command.create(clazz)); + } } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/Constants.java b/core/src/main/java/com/taobao/arthas/core/command/Constants.java index 9ba9e1407..a65fd5347 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/Constants.java +++ b/core/src/main/java/com/taobao/arthas/core/command/Constants.java @@ -43,6 +43,7 @@ public interface Constants { " TRUE : true\n" + " FALSE : false\n" + " TRUE : 'params.length>=0'\n" + - " FALSE : 1==2\n"; + " FALSE : 1==2\n" + + " '#cost>100'\n"; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/basic1000/AuthCommand.java b/core/src/main/java/com/taobao/arthas/core/command/basic1000/AuthCommand.java new file mode 100644 index 000000000..0ca808d0b --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/basic1000/AuthCommand.java @@ -0,0 +1,109 @@ +package com.taobao.arthas.core.command.basic1000; + +import javax.security.auth.Subject; +import javax.security.auth.login.LoginException; + +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.command.Constants; +import com.taobao.arthas.core.security.BasicPrincipal; +import com.taobao.arthas.core.security.SecurityAuthenticator; +import com.taobao.arthas.core.server.ArthasBootstrap; +import com.taobao.arthas.core.shell.cli.Completion; +import com.taobao.arthas.core.shell.cli.CompletionUtils; +import com.taobao.arthas.core.shell.command.AnnotatedCommand; +import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.arthas.core.shell.session.Session; +import com.taobao.middleware.cli.annotations.Argument; +import com.taobao.middleware.cli.annotations.DefaultValue; +import com.taobao.middleware.cli.annotations.Description; +import com.taobao.middleware.cli.annotations.Name; +import com.taobao.middleware.cli.annotations.Option; +import com.taobao.middleware.cli.annotations.Summary; + +/** + * TODO 支持更多的鉴权方式。目前只支持 username/password的方式 + * + * @author hengyunabc 2021-03-03 + * + */ +// @formatter:off +@Name(ArthasConstants.AUTH) +@Summary("Authenticates the current session") +@Description(Constants.EXAMPLE + + " auth" + + " auth \n" + + " auth --username \n" + + Constants.WIKI + Constants.WIKI_HOME + ArthasConstants.AUTH) +//@formatter:on +public class AuthCommand extends AnnotatedCommand { + private static final Logger logger = LoggerFactory.getLogger(AuthCommand.class); + + private String username; + private String password; + private SecurityAuthenticator authenticator = ArthasBootstrap.getInstance().getSecurityAuthenticator(); + + @Argument(argName = "password", index = 0, required = false) + @Description("password") + public void setPassword(String password) { + this.password = password; + } + + @Option(shortName = "n", longName = "username") + @Description("username, default value 'arthas'") + @DefaultValue(ArthasConstants.DEFAULT_USERNAME) + public void setUsername(String username) { + this.username = username; + } + + @Override + public void process(CommandProcess process) { + int status = 0; + String message = ""; + try { + Session session = process.session(); + if (username == null) { + status = 1; + message = "username can not be empty!"; + return; + } + if (password == null) { // 没有传入passowrd参数时,打印当前结果 + boolean authenticated = session.get(ArthasConstants.SUBJECT_KEY) != null; + boolean needLogin = this.authenticator.needLogin(); + + message = "Authentication result: " + authenticated + ", Need authentication: " + needLogin; + if (needLogin && !authenticated) { + status = 1; + } + return; + } else { + // 尝试进行鉴权 + BasicPrincipal principal = new BasicPrincipal(username, password); + try { + Subject subject = authenticator.login(principal); + if (subject != null) { + // 把subject 保存到 session里,后续其它命令则可以正常执行 + session.put(ArthasConstants.SUBJECT_KEY, subject); + message = "Authentication result: " + true + ", username: " + username; + } else { + status = 1; + message = "Authentication result: " + false + ", username: " + username; + } + } catch (LoginException e) { + logger.error("Authentication error, username: {}", username, e); + } + } + } finally { + process.end(status, message); + } + } + + @Override + public void complete(Completion completion) { + if (!CompletionUtils.completeFilePath(completion)) { + super.complete(completion); + } + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java b/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java new file mode 100644 index 000000000..8ad843704 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java @@ -0,0 +1,170 @@ +package com.taobao.arthas.core.command.basic1000; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.IOUtils; +import com.taobao.arthas.core.command.Constants; +import com.taobao.arthas.core.command.model.Base64Model; +import com.taobao.arthas.core.shell.cli.Completion; +import com.taobao.arthas.core.shell.cli.CompletionUtils; +import com.taobao.arthas.core.shell.command.AnnotatedCommand; +import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.middleware.cli.annotations.Argument; +import com.taobao.middleware.cli.annotations.Description; +import com.taobao.middleware.cli.annotations.Name; +import com.taobao.middleware.cli.annotations.Option; +import com.taobao.middleware.cli.annotations.Summary; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.handler.codec.base64.Base64; +import io.netty.util.CharsetUtil; + +/** + * + * @author hengyunabc 2021-01-05 + * + */ +@Name("base64") +@Summary("Encode and decode using Base64 representation") +@Description(Constants.EXAMPLE + + " base64 /tmp/test.txt\n" + + " base64 --input /tmp/test.txt --output /tmp/result.txt\n" + + " base64 -d /tmp/result.txt\n" + + Constants.WIKI + Constants.WIKI_HOME + "base64") +public class Base64Command extends AnnotatedCommand { + private static final Logger logger = LoggerFactory.getLogger(Base64Command.class); + private String file; + private Integer sizeLimit = 128 * 1024; + private int maxSizeLimit = 8 * 1024 * 1024; + + private boolean decode; + + private String input; + private String output; + + @Argument(argName = "file", index = 0, required = false) + @Description("file") + public void setFiles(String file) { + this.file = file; + } + + @Option(shortName = "d", longName = "decode", flag = true) + @Description("decodes input") + public void setDecode(boolean decode) { + this.decode = decode; + } + + @Option(shortName = "i", longName = "input") + @Description("input file") + public void setInput(String input) { + this.input = input; + } + + @Option(shortName = "o", longName = "output") + @Description("output file") + public void setOutput(String output) { + this.output = output; + } + + @Option(shortName = "M", longName = "sizeLimit") + @Description("Upper size limit in bytes for the result (128 * 1024 by default, the maximum value is 8 * 1024 * 1024)") + public void setSizeLimit(Integer sizeLimit) { + this.sizeLimit = sizeLimit; + } + + @Override + public void process(CommandProcess process) { + if (!verifyOptions(process)) { + return; + } + + // 确认输入 + if (file == null && this.input != null) { + file = input; + } + + File f = new File(file); + if (!f.exists()) { + process.end(-1, file + ": No such file or directory"); + return; + } + if (f.isDirectory()) { + process.end(-1, file + ": Is a directory"); + return; + } + + if (f.length() > sizeLimit) { + process.end(-1, file + ": Is too large, size: " + f.length()); + return; + } + + InputStream input = null; + + try { + input = new FileInputStream(f); + byte[] bytes = IOUtils.getBytes(input); + + ByteBuf convertResult = null; + if (this.decode) { + convertResult = Base64.decode(Unpooled.wrappedBuffer(bytes)); + } else { + convertResult = Base64.encode(Unpooled.wrappedBuffer(bytes)); + } + + if (this.output != null) { + int readableBytes = convertResult.readableBytes(); + OutputStream out = new FileOutputStream(this.output); + convertResult.readBytes(out, readableBytes); + process.appendResult(new Base64Model(null)); + } else { + String base64Str = convertResult.toString(CharsetUtil.UTF_8); + process.appendResult(new Base64Model(base64Str)); + } + } catch (IOException e) { + logger.error("read file error. name: " + file, e); + process.end(1, "read file error: " + e.getMessage()); + return; + } finally { + IOUtils.close(input); + } + + process.end(); + } + + private boolean verifyOptions(CommandProcess process) { + if(this.file == null && this.input == null) { + process.end(-1); + return false; + } + + if (sizeLimit > maxSizeLimit) { + process.end(-1, "sizeLimit cannot be large than: " + maxSizeLimit); + return false; + } + + // 目前不支持过滤,限制http请求执行的文件大小 + int maxSizeLimitOfNonTty = 128 * 1024; + if (!process.session().isTty() && sizeLimit > maxSizeLimitOfNonTty) { + process.end(-1, + "When executing in non-tty session, sizeLimit cannot be large than: " + maxSizeLimitOfNonTty); + return false; + } + return true; + } + + @Override + public void complete(Completion completion) { + if (!CompletionUtils.completeFilePath(completion)) { + super.complete(completion); + } + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/basic1000/SessionCommand.java b/core/src/main/java/com/taobao/arthas/core/command/basic1000/SessionCommand.java index e532d6c9b..44a773a8f 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/basic1000/SessionCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/basic1000/SessionCommand.java @@ -35,6 +35,7 @@ public class SessionCommand extends AnnotatedCommand { result.setAgentId(id); } result.setTunnelServer(tunnelClient.getTunnelServerUrl()); + result.setTunnelConnected(tunnelClient.isConnected()); } //statUrl diff --git a/core/src/main/java/com/taobao/arthas/core/command/basic1000/ShutdownCommand.java b/core/src/main/java/com/taobao/arthas/core/command/basic1000/ShutdownCommand.java deleted file mode 100644 index 65d23aea2..000000000 --- a/core/src/main/java/com/taobao/arthas/core/command/basic1000/ShutdownCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.taobao.arthas.core.command.basic1000; - -import com.alibaba.arthas.deps.org.slf4j.Logger; -import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; -import com.taobao.arthas.core.command.model.MessageModel; -import com.taobao.arthas.core.command.model.ResetModel; -import com.taobao.arthas.core.command.model.ShutdownModel; -import com.taobao.arthas.core.server.ArthasBootstrap; -import com.taobao.arthas.core.shell.command.AnnotatedCommand; -import com.taobao.arthas.core.shell.command.CommandProcess; -import com.taobao.arthas.core.util.affect.EnhancerAffect; -import com.taobao.middleware.cli.annotations.Hidden; -import com.taobao.middleware.cli.annotations.Name; -import com.taobao.middleware.cli.annotations.Summary; - -/** - * 关闭命令 - * - * @author vlinux on 14/10/23. - * @see StopCommand - */ -@Name("shutdown") -@Summary("Shutdown Arthas server and exit the console") -@Hidden -public class ShutdownCommand extends AnnotatedCommand { - - private static final Logger logger = LoggerFactory.getLogger(ShutdownCommand.class); - - @Override - public void process(CommandProcess process) { - shutdown(process); - } - - public static void shutdown(CommandProcess process) { - ArthasBootstrap arthasBootstrap = ArthasBootstrap.getInstance(); - try { - // 退出之前需要重置所有的增强类 - process.appendResult(new MessageModel("Resetting all enhanced classes ...")); - EnhancerAffect enhancerAffect = arthasBootstrap.reset(); - process.appendResult(new ResetModel(enhancerAffect)); - process.appendResult(new ShutdownModel(true, "Arthas Server is going to shut down...")); - } catch (Throwable e) { - logger.error("An error occurred when stopping arthas server.", e); - process.appendResult(new ShutdownModel(false, "An error occurred when stopping arthas server.")); - } finally { - process.end(); - arthasBootstrap.destroy(); - } - } -} diff --git a/core/src/main/java/com/taobao/arthas/core/command/basic1000/StopCommand.java b/core/src/main/java/com/taobao/arthas/core/command/basic1000/StopCommand.java index 42a4260e8..d5b2f51db 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/basic1000/StopCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/basic1000/StopCommand.java @@ -1,20 +1,42 @@ package com.taobao.arthas.core.command.basic1000; +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.core.command.model.MessageModel; +import com.taobao.arthas.core.command.model.ResetModel; +import com.taobao.arthas.core.command.model.ShutdownModel; +import com.taobao.arthas.core.server.ArthasBootstrap; import com.taobao.arthas.core.shell.command.AnnotatedCommand; import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.arthas.core.util.affect.EnhancerAffect; import com.taobao.middleware.cli.annotations.Name; import com.taobao.middleware.cli.annotations.Summary; /** - * Alias for ShutdownCommand * @author hengyunabc 2019-07-05 - * @see ShutdownCommand */ @Name("stop") @Summary("Stop/Shutdown Arthas server and exit the console.") public class StopCommand extends AnnotatedCommand { + private static final Logger logger = LoggerFactory.getLogger(StopCommand.class); @Override public void process(CommandProcess process) { - ShutdownCommand.shutdown(process); + shutdown(process); + } + private static void shutdown(CommandProcess process) { + ArthasBootstrap arthasBootstrap = ArthasBootstrap.getInstance(); + try { + // 退出之前需要重置所有的增强类 + process.appendResult(new MessageModel("Resetting all enhanced classes ...")); + EnhancerAffect enhancerAffect = arthasBootstrap.reset(); + process.appendResult(new ResetModel(enhancerAffect)); + process.appendResult(new ShutdownModel(true, "Arthas Server is going to shutdown...")); + } catch (Throwable e) { + logger.error("An error occurred when stopping arthas server.", e); + process.appendResult(new ShutdownModel(false, "An error occurred when stopping arthas server.")); + } finally { + process.end(); + arthasBootstrap.destroy(); + } } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/express/ExpressFactory.java b/core/src/main/java/com/taobao/arthas/core/command/express/ExpressFactory.java index 5d6ffd63d..d2d578bc1 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/express/ExpressFactory.java +++ b/core/src/main/java/com/taobao/arthas/core/command/express/ExpressFactory.java @@ -24,6 +24,9 @@ public class ExpressFactory { } public static Express unpooledExpress(ClassLoader classloader) { + if (classloader == null) { + classloader = ClassLoader.getSystemClassLoader(); + } return new OgnlExpress(new ClassLoaderClassResolver(classloader)); } } \ No newline at end of file diff --git a/core/src/main/java/com/taobao/arthas/core/command/klass100/JadCommand.java b/core/src/main/java/com/taobao/arthas/core/command/klass100/JadCommand.java index ce62103e0..8e19aed7b 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/klass100/JadCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/klass100/JadCommand.java @@ -2,6 +2,7 @@ package com.taobao.arthas.core.command.klass100; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.Pair; import com.taobao.arthas.core.command.Constants; import com.taobao.arthas.core.command.model.ClassVO; import com.taobao.arthas.core.command.model.ClassLoaderVO; @@ -21,6 +22,7 @@ import com.taobao.arthas.core.util.InstrumentationUtils; import com.taobao.arthas.core.util.SearchUtils; import com.taobao.arthas.core.util.affect.RowAffect; import com.taobao.middleware.cli.annotations.Argument; +import com.taobao.middleware.cli.annotations.DefaultValue; import com.taobao.middleware.cli.annotations.Description; import com.taobao.middleware.cli.annotations.Name; import com.taobao.middleware.cli.annotations.Option; @@ -31,6 +33,7 @@ import java.lang.instrument.Instrumentation; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.NavigableMap; import java.util.Set; import java.util.Collection; import java.util.regex.Pattern; @@ -58,6 +61,7 @@ public class JadCommand extends AnnotatedCommand { private String classLoaderClass; private boolean isRegEx = false; private boolean hideUnicode = false; + private boolean lineNumber; /** * jad output source code only @@ -107,6 +111,13 @@ public class JadCommand extends AnnotatedCommand { this.sourceOnly = sourceOnly; } + @Option(longName = "lineNumber") + @DefaultValue("true") + @Description("Output source code contins line number, default value true") + public void setLineNumber(boolean lineNumber) { + this.lineNumber = lineNumber; + } + @Override public void process(CommandProcess process) { RowAffect affect = new RowAffect(); @@ -168,7 +179,8 @@ public class JadCommand extends AnnotatedCommand { Map, File> classFiles = transformer.getDumpResult(); File classFile = classFiles.get(c); - String source = Decompiler.decompile(classFile.getAbsolutePath(), methodName, hideUnicode); + Pair> decompileResult = Decompiler.decompileWithMappings(classFile.getAbsolutePath(), methodName, hideUnicode, lineNumber); + String source = decompileResult.getFirst(); if (source != null) { source = pattern.matcher(source).replaceAll(""); } else { @@ -177,6 +189,7 @@ public class JadCommand extends AnnotatedCommand { JadModel jadModel = new JadModel(); jadModel.setSource(source); + jadModel.setMappings(decompileResult.getSecond()); if (!this.sourceOnly) { jadModel.setClassInfo(ClassUtils.createSimpleClassInfo(c)); jadModel.setLocation(ClassUtils.getCodeSource(c.getProtectionDomain().getCodeSource())); diff --git a/core/src/main/java/com/taobao/arthas/core/command/klass100/RedefineCommand.java b/core/src/main/java/com/taobao/arthas/core/command/klass100/RedefineCommand.java index 60ac3762d..5b0a3d19f 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/klass100/RedefineCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/klass100/RedefineCommand.java @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Collection; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassReader; +import com.alibaba.deps.org.objectweb.asm.ClassReader; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; import com.taobao.arthas.core.command.Constants; @@ -40,6 +40,7 @@ import com.taobao.middleware.cli.annotations.Summary; @Description(Constants.EXAMPLE + " redefine /tmp/Test.class\n" + " redefine -c 327a647b /tmp/Test.class /tmp/Test\\$Inner.class \n" + + " redefine --classLoaderClass 'sun.misc.Launcher$AppClassLoader' /tmp/Test.class \n" + Constants.WIKI + Constants.WIKI_HOME + "redefine") public class RedefineCommand extends AnnotatedCommand { private static final Logger logger = LoggerFactory.getLogger(RedefineCommand.class); diff --git a/core/src/main/java/com/taobao/arthas/core/command/klass100/RetransformCommand.java b/core/src/main/java/com/taobao/arthas/core/command/klass100/RetransformCommand.java new file mode 100644 index 000000000..fc4272587 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/klass100/RetransformCommand.java @@ -0,0 +1,502 @@ +package com.taobao.arthas.core.command.klass100; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.lang.instrument.ClassFileTransformer; +import java.lang.instrument.IllegalClassFormatException; +import java.lang.instrument.Instrumentation; +import java.security.ProtectionDomain; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.alibaba.deps.org.objectweb.asm.ClassReader; +import com.taobao.arthas.core.advisor.TransformerManager; +import com.taobao.arthas.core.command.Constants; +import com.taobao.arthas.core.command.model.ClassLoaderVO; +import com.taobao.arthas.core.command.model.RetransformModel; +import com.taobao.arthas.core.server.ArthasBootstrap; +import com.taobao.arthas.core.shell.cli.CliToken; +import com.taobao.arthas.core.shell.cli.Completion; +import com.taobao.arthas.core.shell.cli.CompletionUtils; +import com.taobao.arthas.core.shell.command.AnnotatedCommand; +import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.arthas.core.util.ClassLoaderUtils; +import com.taobao.arthas.core.util.ClassUtils; +import com.taobao.arthas.core.util.SearchUtils; +import com.taobao.middleware.cli.annotations.Argument; +import com.taobao.middleware.cli.annotations.DefaultValue; +import com.taobao.middleware.cli.annotations.Description; +import com.taobao.middleware.cli.annotations.Name; +import com.taobao.middleware.cli.annotations.Option; +import com.taobao.middleware.cli.annotations.Summary; + +/** + * + * Retransform Classes. + * + * @author hengyunabc 2021-01-05 + * @see java.lang.instrument.Instrumentation#retransformClasses(Class...) + */ +@Name("retransform") +@Summary("Retransform classes. @see Instrumentation#retransformClasses(Class...)") +@Description(Constants.EXAMPLE + " retransform /tmp/Test.class\n" + + " retransform -l \n" + + " retransform -d 1 # delete retransform entry\n" + + " retransform --deleteAll # delete all retransform entries\n" + + " retransform --classPattern demo.* # triger retransform classes\n" + + " retransform -c 327a647b /tmp/Test.class /tmp/Test\\$Inner.class \n" + + " retransform --classLoaderClass 'sun.misc.Launcher$AppClassLoader' /tmp/Test.class\n" + + Constants.WIKI + Constants.WIKI_HOME + + "retransform") +public class RetransformCommand extends AnnotatedCommand { + private static final Logger logger = LoggerFactory.getLogger(RetransformCommand.class); + private static final int MAX_FILE_SIZE = 10 * 1024 * 1024; + + private static volatile List retransformEntries = new ArrayList(); + private static volatile ClassFileTransformer transformer = null; + + private String hashCode; + private String classLoaderClass; + + private List paths; + + private boolean list; + + private int delete = -1; + + private boolean deleteAll; + + private String classPattern; + + private int limit; + + @Option(shortName = "l", longName = "list", flag = true) + @Description("list all retransform entry.") + public void setList(boolean list) { + this.list = list; + } + + @Option(shortName = "d", longName = "delete") + @Description("delete retransform entry by id.") + public void setDelete(int delete) { + this.delete = delete; + } + + @Option(longName = "deleteAll", flag = true) + @Description("delete all retransform entries.") + public void setDeleteAll(boolean deleteAll) { + this.deleteAll = deleteAll; + } + + @Option(longName = "classPattern") + @Description("trigger retransform matched classes by class pattern.") + public void setClassPattern(String classPattern) { + this.classPattern = classPattern; + } + + @Option(shortName = "c", longName = "classloader") + @Description("classLoader hashcode") + public void setHashCode(String hashCode) { + this.hashCode = hashCode; + } + + @Option(longName = "classLoaderClass") + @Description("The class name of the special class's classLoader.") + public void setClassLoaderClass(String classLoaderClass) { + this.classLoaderClass = classLoaderClass; + } + + @Argument(argName = "classfilePaths", index = 0, required = false) + @Description(".class file paths") + public void setPaths(List paths) { + this.paths = paths; + } + + @Option(longName = "limit") + @Description("The limit of dump classes size, default value is 5") + @DefaultValue("50") + public void setLimit(int limit) { + this.limit = limit; + } + + private static void initTransformer() { + if (transformer != null) { + return; + } else { + synchronized (RetransformCommand.class) { + if (transformer == null) { + transformer = new RetransformClassFileTransformer(); + TransformerManager transformerManager = ArthasBootstrap.getInstance().getTransformerManager(); + transformerManager.addRetransformer(transformer); + } + } + } + } + + @Override + public void process(CommandProcess process) { + initTransformer(); + + RetransformModel retransformModel = new RetransformModel(); + Instrumentation inst = process.session().getInstrumentation(); + + if (this.list) { + List retransformEntryList = allRetransformEntries(); + retransformModel.setRetransformEntries(retransformEntryList); + process.appendResult(retransformModel); + process.end(); + return; + } else if (this.deleteAll) { + deleteAllRetransformEntry(); + process.appendResult(retransformModel); + process.end(); + return; + } else if (this.delete > 0) { + deleteRetransformEntry(this.delete); + process.end(); + return; + } else if (this.classPattern != null) { + Set> searchClass = SearchUtils.searchClass(inst, classPattern, false, this.hashCode); + if (searchClass.isEmpty()) { + process.end(-1, "These classes are not found in the JVM and may not be loaded: " + classPattern); + return; + } + + if (searchClass.size() > limit) { + process.end(-1, "match classes size: " + searchClass.size() + ", more than limit: " + limit + + ", It is recommended to use a more precise class pattern."); + } + try { + inst.retransformClasses(searchClass.toArray(new Class[0])); + for (Class clazz : searchClass) { + retransformModel.addRetransformClass(clazz.getName()); + } + process.appendResult(retransformModel); + process.end(); + return; + } catch (Throwable e) { + String message = "retransform error! " + e.toString(); + logger.error(message, e); + process.end(-1, message); + return; + } + } + + for (String path : paths) { + File file = new File(path); + if (!file.exists()) { + process.end(-1, "file does not exist, path:" + path); + return; + } + if (!file.isFile()) { + process.end(-1, "not a normal file, path:" + path); + return; + } + if (file.length() >= MAX_FILE_SIZE) { + process.end(-1, "file size: " + file.length() + " >= " + MAX_FILE_SIZE + ", path: " + path); + return; + } + } + + Map bytesMap = new HashMap(); + for (String path : paths) { + RandomAccessFile f = null; + try { + f = new RandomAccessFile(path, "r"); + final byte[] bytes = new byte[(int) f.length()]; + f.readFully(bytes); + + final String clazzName = readClassName(bytes); + + bytesMap.put(clazzName, bytes); + + } catch (Exception e) { + logger.warn("load class file failed: " + path, e); + process.end(-1, "load class file failed: " + path + ", error: " + e); + return; + } finally { + if (f != null) { + try { + f.close(); + } catch (IOException e) { + // ignore + } + } + } + } + + if (bytesMap.size() != paths.size()) { + process.end(-1, "paths may contains same class name!"); + return; + } + + List retransformEntryList = new ArrayList(); + + List> classList = new ArrayList>(); + + for (Class clazz : inst.getAllLoadedClasses()) { + if (bytesMap.containsKey(clazz.getName())) { + + if (hashCode == null && classLoaderClass != null) { + List matchedClassLoaders = ClassLoaderUtils.getClassLoaderByClassName(inst, + classLoaderClass); + if (matchedClassLoaders.size() == 1) { + hashCode = Integer.toHexString(matchedClassLoaders.get(0).hashCode()); + } else if (matchedClassLoaders.size() > 1) { + Collection classLoaderVOList = ClassUtils + .createClassLoaderVOList(matchedClassLoaders); + retransformModel.setClassLoaderClass(classLoaderClass) + .setMatchedClassLoaders(classLoaderVOList); + process.appendResult(retransformModel); + process.end(-1, + "Found more than one classloader by class name, please specify classloader with '-c '"); + return; + } else { + process.end(-1, "Can not find classloader by class name: " + classLoaderClass + "."); + return; + } + } + + ClassLoader classLoader = clazz.getClassLoader(); + if (classLoader != null && hashCode != null + && !Integer.toHexString(classLoader.hashCode()).equals(hashCode)) { + continue; + } + + RetransformEntry retransformEntry = new RetransformEntry(clazz.getName(), bytesMap.get(clazz.getName()), + hashCode, classLoaderClass); + retransformEntryList.add(retransformEntry); + classList.add(clazz); + retransformModel.addRetransformClass(clazz.getName()); + + logger.info("Try retransform class name: {}, ClassLoader: {}", clazz.getName(), clazz.getClassLoader()); + } + } + + try { + if (retransformEntryList.isEmpty()) { + process.end(-1, "These classes are not found in the JVM and may not be loaded: " + bytesMap.keySet()); + return; + } + addRetransformEntry(retransformEntryList); + + inst.retransformClasses(classList.toArray(new Class[0])); + + process.appendResult(retransformModel); + process.end(); + } catch (Throwable e) { + String message = "retransform error! " + e.toString(); + logger.error(message, e); + process.end(-1, message); + } + + } + + private static String readClassName(final byte[] bytes) { + return new ClassReader(bytes).getClassName().replace('/', '.'); + } + + @Override + public void complete(Completion completion) { + List tokens = completion.lineTokens(); + + if (CompletionUtils.shouldCompleteOption(completion, "--classPattern")) { + CompletionUtils.completeClassName(completion); + return; + } + + for (CliToken token : tokens) { + String tokenStr = token.value(); + if (tokenStr != null && tokenStr.startsWith("-")) { + super.complete(completion); + return; + } + } + + // 最后,没有有 - 开头的,才尝试补全 file path + if (!CompletionUtils.completeFilePath(completion)) { + super.complete(completion); + } + } + + public static class RetransformEntry { + private static final AtomicInteger counter = new AtomicInteger(0); + private int id; + private String className; + private byte[] bytes; + private String hashCode; + private String classLoaderClass; + + /** + * 被 transform 触发次数 + */ + private int transformCount = 0; + + public RetransformEntry(String className, byte[] bytes, String hashCode, String classLoaderClass) { + id = counter.incrementAndGet(); + this.className = className; + this.bytes = bytes; + this.hashCode = hashCode; + this.classLoaderClass = classLoaderClass; + } + + public void incTransformCount() { + transformCount++; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getTransformCount() { + return transformCount; + } + + public void setTransformCount(int transformCount) { + this.transformCount = transformCount; + } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public byte[] getBytes() { + return bytes; + } + + public void setBytes(byte[] bytes) { + this.bytes = bytes; + } + + public String getHashCode() { + return hashCode; + } + + public void setHashCode(String hashCode) { + this.hashCode = hashCode; + } + + public String getClassLoaderClass() { + return classLoaderClass; + } + + public void setClassLoaderClass(String classLoaderClass) { + this.classLoaderClass = classLoaderClass; + } + } + + public static synchronized void addRetransformEntry(List retransformEntryList) { + List tmp = new ArrayList(); + tmp.addAll(retransformEntries); + tmp.addAll(retransformEntryList); + Collections.sort(tmp, new Comparator() { + @Override + public int compare(RetransformEntry entry1, RetransformEntry entry2) { + return entry1.getId() - entry2.getId(); + } + }); + retransformEntries = tmp; + } + + public static synchronized RetransformEntry deleteRetransformEntry(int id) { + RetransformEntry result = null; + List tmp = new ArrayList(); + for (RetransformEntry entry : retransformEntries) { + if (entry.getId() != id) { + tmp.add(entry); + } else { + result = entry; + } + } + retransformEntries = tmp; + return result; + } + + public static List allRetransformEntries() { + return retransformEntries; + } + + public static synchronized void deleteAllRetransformEntry() { + retransformEntries = new ArrayList(); + } + + static class RetransformClassFileTransformer implements ClassFileTransformer { + @Override + public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, + ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { + + if (className == null) { + return null; + } + + className = className.replace('/', '.'); + + List allRetransformEntries = allRetransformEntries(); + // 倒序,因为要执行的配置生效 + ListIterator listIterator = allRetransformEntries + .listIterator(allRetransformEntries.size()); + while (listIterator.hasPrevious()) { + RetransformEntry retransformEntry = listIterator.previous(); + int id = retransformEntry.getId(); + // 判断类名是否一致 + boolean updateFlag = false; + // 类名一致,则看是否要比较 loader,如果不需要比较 loader,则认为成功 + if (className.equals(retransformEntry.getClassName())) { + if (retransformEntry.getClassLoaderClass() != null || retransformEntry.getHashCode() != null) { + updateFlag = isLoaderMatch(retransformEntry, loader); + } else { + updateFlag = true; + } + } + + if (updateFlag) { + logger.info("RetransformCommand match class: {}, id: {}, classLoaderClass: {}, hashCode: {}", + className, id, retransformEntry.getClassLoaderClass(), retransformEntry.getHashCode()); + retransformEntry.incTransformCount(); + return retransformEntry.getBytes(); + } + + } + + return null; + } + + private boolean isLoaderMatch(RetransformEntry retransformEntry, ClassLoader loader) { + if (loader == null) { + return false; + } + if (retransformEntry.getClassLoaderClass() != null) { + if (loader.getClass().getName().equals(retransformEntry.getClassLoaderClass())) { + return true; + } + } + if (retransformEntry.getHashCode() != null) { + String hashCode = Integer.toHexString(loader.hashCode()); + if (hashCode.equals(retransformEntry.getHashCode())) { + return true; + } + } + return false; + } + + } +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/logger/AsmRenameUtil.java b/core/src/main/java/com/taobao/arthas/core/command/logger/AsmRenameUtil.java index 8a3f3da1d..637c2e42b 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/logger/AsmRenameUtil.java +++ b/core/src/main/java/com/taobao/arthas/core/command/logger/AsmRenameUtil.java @@ -1,10 +1,10 @@ package com.taobao.arthas.core.command.logger; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassReader; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassVisitor; -import com.alibaba.arthas.deps.org.objectweb.asm.ClassWriter; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.ClassRemapper; -import com.alibaba.arthas.deps.org.objectweb.asm.commons.SimpleRemapper; +import com.alibaba.deps.org.objectweb.asm.ClassReader; +import com.alibaba.deps.org.objectweb.asm.ClassVisitor; +import com.alibaba.deps.org.objectweb.asm.ClassWriter; +import com.alibaba.deps.org.objectweb.asm.commons.ClassRemapper; +import com.alibaba.deps.org.objectweb.asm.commons.SimpleRemapper; /** * diff --git a/core/src/main/java/com/taobao/arthas/core/command/logger/LoggerCommand.java b/core/src/main/java/com/taobao/arthas/core/command/logger/LoggerCommand.java index b599a563b..53ac443b1 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/logger/LoggerCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/logger/LoggerCommand.java @@ -119,7 +119,7 @@ public class LoggerCommand extends AnnotatedCommand { if (this.name != null && this.level != null) { level(process); } else { - loggers(process, name); + loggers(process); } } @@ -160,7 +160,7 @@ public class LoggerCommand extends AnnotatedCommand { } } - public void loggers(CommandProcess process, String name) { + public void loggers(CommandProcess process) { Map classLoaderLoggerMap = new LinkedHashMap(); for (Class clazz : process.session().getInstrumentation().getAllLoadedClasses()) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/Base64Model.java b/core/src/main/java/com/taobao/arthas/core/command/model/Base64Model.java new file mode 100644 index 000000000..11852a940 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/model/Base64Model.java @@ -0,0 +1,31 @@ +package com.taobao.arthas.core.command.model; + +/** + * + * @author hengyunabc 2021-01-05 + * + */ +public class Base64Model extends ResultModel { + + private String content; + + public Base64Model() { + } + + public Base64Model(String content) { + this.content = content; + } + + @Override + public String getType() { + return "base64"; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/JadModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/JadModel.java index 19a8691ba..d96630c27 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/JadModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/JadModel.java @@ -1,15 +1,17 @@ package com.taobao.arthas.core.command.model; import java.util.Collection; -import java.util.List; +import java.util.NavigableMap; /** * @author gongdewei 2020/4/22 + * @author hengyunabc 2021-02-23 */ public class JadModel extends ResultModel { private ClassVO classInfo; private String location; private String source; + private NavigableMap mappings; private Collection matchedClassLoaders; private String classLoaderClass; @@ -48,6 +50,14 @@ public class JadModel extends ResultModel { this.source = source; } + public NavigableMap getMappings() { + return mappings; + } + + public void setMappings(NavigableMap mappings) { + this.mappings = mappings; + } + public Collection getMatchedClasses() { return matchedClasses; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/RetransformModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/RetransformModel.java new file mode 100644 index 000000000..c36885931 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/model/RetransformModel.java @@ -0,0 +1,96 @@ +package com.taobao.arthas.core.command.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.taobao.arthas.core.command.klass100.RetransformCommand.RetransformEntry; +import com.taobao.arthas.core.util.ClassUtils; + +/** + * + * @author hengyunabc 2021-01-06 + * + */ +public class RetransformModel extends ResultModel { + + private int retransformCount; + + private List retransformClasses; + private Collection matchedClassLoaders; + private String classLoaderClass; + + private List retransformEntries; + + private RetransformEntry deletedRetransformEntry; + +// private List trigger + +// List classVOs = ClassUtils.createClassVOList(matchedClasses); + public RetransformModel() { + } + + public void addRetransformClass(String className) { + if (retransformClasses == null) { + retransformClasses = new ArrayList(); + } + retransformClasses.add(className); + retransformCount++; + } + + public int getRetransformCount() { + return retransformCount; + } + + public void setRetransformCount(int retransformCount) { + this.retransformCount = retransformCount; + } + + public List getRetransformClasses() { + return retransformClasses; + } + + public void setRetransformClasses(List retransformClasses) { + this.retransformClasses = retransformClasses; + } + + public String getClassLoaderClass() { + return classLoaderClass; + } + + public RetransformModel setClassLoaderClass(String classLoaderClass) { + this.classLoaderClass = classLoaderClass; + return this; + } + + public Collection getMatchedClassLoaders() { + return matchedClassLoaders; + } + + public RetransformModel setMatchedClassLoaders(Collection matchedClassLoaders) { + this.matchedClassLoaders = matchedClassLoaders; + return this; + } + + public List getRetransformEntries() { + return retransformEntries; + } + + public void setRetransformEntries(List retransformEntries) { + this.retransformEntries = retransformEntries; + } + + public RetransformEntry getDeletedRetransformEntry() { + return deletedRetransformEntry; + } + + public void setDeletedRetransformEntry(RetransformEntry deletedRetransformEntry) { + this.deletedRetransformEntry = deletedRetransformEntry; + } + + @Override + public String getType() { + return "retransform"; + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/RuntimeInfoVO.java b/core/src/main/java/com/taobao/arthas/core/command/model/RuntimeInfoVO.java index 6b35f0f74..38ed25ecf 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/RuntimeInfoVO.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/RuntimeInfoVO.java @@ -13,6 +13,7 @@ public class RuntimeInfoVO { private double systemLoadAverage; private int processors; private long uptime; + private long timestamp; public RuntimeInfoVO() { } @@ -72,4 +73,12 @@ public class RuntimeInfoVO { public void setUptime(long uptime) { this.uptime = uptime; } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/SessionModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/SessionModel.java index 0652f991c..aede0262a 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/SessionModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/SessionModel.java @@ -13,6 +13,8 @@ public class SessionModel extends ResultModel { private String tunnelServer; private String statUrl; + private boolean tunnelConnected; + @Override public String getType() { return "session"; @@ -57,4 +59,12 @@ public class SessionModel extends ResultModel { public void setStatUrl(String statUrl) { this.statUrl = statUrl; } + + public boolean isTunnelConnected() { + return tunnelConnected; + } + + public void setTunnelConnected(boolean tunnelConnected) { + this.tunnelConnected = tunnelConnected; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java index f794086fb..a5f7ce1cc 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java @@ -15,6 +15,9 @@ public class WatchModel extends ResultModel { private int expand; private int sizeLimit; + private String className; + private String methodName; + private String accessPoint; public WatchModel() { } @@ -63,4 +66,28 @@ public class WatchModel extends ResultModel { public void setSizeLimit(int sizeLimit) { this.sizeLimit = sizeLimit; } + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public String getAccessPoint() { + return accessPoint; + } + + public void setAccessPoint(String accessPoint) { + this.accessPoint = accessPoint; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java index 11bafd572..7147b5cef 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/WelcomeModel.java @@ -10,6 +10,7 @@ public class WelcomeModel extends ResultModel { private String version; private String wiki; private String tutorials; + private String mainClass; public WelcomeModel() { } @@ -58,4 +59,12 @@ public class WelcomeModel extends ResultModel { public void setTutorials(String tutorials) { this.tutorials = tutorials; } + + public String getMainClass() { + return mainClass; + } + + public void setMainClass(String mainClass) { + this.mainClass = mainClass; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/AbstractTraceAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/AbstractTraceAdviceListener.java index 6cd3a3888..023d03da7 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/AbstractTraceAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/AbstractTraceAdviceListener.java @@ -63,7 +63,12 @@ public class AbstractTraceAdviceListener extends AdviceListenerAdapter { @Override public void afterThrowing(ClassLoader loader, Class clazz, ArthasMethod method, Object target, Object[] args, Throwable throwable) throws Throwable { - int lineNumber = throwable.getStackTrace()[0].getLineNumber(); + int lineNumber = -1; + StackTraceElement[] stackTrace = throwable.getStackTrace(); + if (stackTrace.length != 0) { + lineNumber = stackTrace[0].getLineNumber(); + } + threadLocalTraceEntity(loader).tree.end(throwable, lineNumber); final Advice advice = Advice.newForAfterThrowing(loader, clazz, method, target, args, throwable); finishing(loader, advice); @@ -76,8 +81,11 @@ public class AbstractTraceAdviceListener extends AdviceListenerAdapter { private void finishing(ClassLoader loader, Advice advice) { // 本次调用的耗时 TraceEntity traceEntity = threadLocalTraceEntity(loader); - double cost = threadLocalWatch.costInMillis(); - if (--traceEntity.deep == 0) { + if (traceEntity.deep >= 1) { // #1817 防止deep为负数 + traceEntity.deep--; + } + if (traceEntity.deep == 0) { + double cost = threadLocalWatch.costInMillis(); try { boolean conditionResult = isConditionMet(command.getConditionExpress(), advice, cost); if (this.isVerbose()) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/DashboardCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/DashboardCommand.java index f8be83e1e..571c3b055 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/DashboardCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/DashboardCommand.java @@ -32,6 +32,7 @@ import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryType; import java.lang.management.MemoryUsage; import java.util.ArrayList; +import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -206,6 +207,7 @@ public class DashboardCommand extends AnnotatedCommand { runtimeInfo.setSystemLoadAverage(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()); runtimeInfo.setProcessors(Runtime.getRuntime().availableProcessors()); runtimeInfo.setUptime(ManagementFactory.getRuntimeMXBean().getUptime() / 1000); + runtimeInfo.setTimestamp(new Date().getTime()); dashboardModel.setRuntimeInfo(runtimeInfo); } @@ -306,8 +308,8 @@ public class DashboardCommand extends AnnotatedCommand { DashboardModel dashboardModel = new DashboardModel(); //thread sample - Map threads = ThreadUtil.getThreads(); - dashboardModel.setThreads(threadSampler.sample(threads.values())); + List threads = ThreadUtil.getThreads(); + dashboardModel.setThreads(threadSampler.sample(threads)); //memory addMemoryInfo(dashboardModel); @@ -319,7 +321,11 @@ public class DashboardCommand extends AnnotatedCommand { addRuntimeInfo(dashboardModel); //tomcat - addTomcatInfo(dashboardModel); + try { + addTomcatInfo(dashboardModel); + } catch (Throwable e) { + logger.error("try to read tomcat info error", e); + } process.appendResult(dashboardModel); diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/EnhancerCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/EnhancerCommand.java index 056543938..2c7904875 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/EnhancerCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/EnhancerCommand.java @@ -1,7 +1,6 @@ package com.taobao.arthas.core.command.monitor200; import java.lang.instrument.Instrumentation; -import java.lang.instrument.UnmodifiableClassException; import java.util.Collections; import java.util.List; @@ -21,10 +20,17 @@ import com.taobao.arthas.core.shell.handlers.shell.QExitHandler; import com.taobao.arthas.core.shell.session.Session; import com.taobao.arthas.core.util.Constants; import com.taobao.arthas.core.util.LogUtil; +import com.taobao.arthas.core.util.SearchUtils; import com.taobao.arthas.core.util.affect.EnhancerAffect; import com.taobao.arthas.core.util.matcher.Matcher; +import com.taobao.arthas.core.view.Ansi; +import com.taobao.middleware.cli.annotations.Argument; import com.taobao.middleware.cli.annotations.Description; import com.taobao.middleware.cli.annotations.Option; +import com.taobao.text.Color; +import com.taobao.text.Decoration; +import com.taobao.text.ui.LabelElement; +import com.taobao.text.util.RenderUtil; /** * @author beiwei30 on 29/11/2016. @@ -35,14 +41,22 @@ public abstract class EnhancerCommand extends AnnotatedCommand { protected static final List EMPTY = Collections.emptyList(); public static final String[] EXPRESS_EXAMPLES = { "params", "returnObj", "throwExp", "target", "clazz", "method", "{params,returnObj}", "params[0]" }; + private String excludeClassPattern; protected Matcher classNameMatcher; + protected Matcher classNameExcludeMatcher; protected Matcher methodNameMatcher; protected long listenerId; protected boolean verbose; + @Option(longName = "exclude-class-pattern") + @Description("exclude class name pattern, use either '.' or '/' as separator") + public void setExcludeClassPattern(String excludeClassPattern) { + this.excludeClassPattern = excludeClassPattern; + } + @Option(longName = "listenerId") @Description("The special listenerId") public void setListenerId(long listenerId) { @@ -62,6 +76,11 @@ public abstract class EnhancerCommand extends AnnotatedCommand { */ protected abstract Matcher getClassNameMatcher(); + /** + * 排除类名匹配 + */ + protected abstract Matcher getClassNameExcludeMatcher(); + /** * 方法名匹配 * @@ -143,7 +162,7 @@ public abstract class EnhancerCommand extends AnnotatedCommand { skipJDKTrace = ((AbstractTraceAdviceListener) listener).getCommand().isSkipJDKTrace(); } - Enhancer enhancer = new Enhancer(listener, listener instanceof InvokeTraceable, skipJDKTrace, getClassNameMatcher(), getMethodNameMatcher()); + Enhancer enhancer = new Enhancer(listener, listener instanceof InvokeTraceable, skipJDKTrace, getClassNameMatcher(), getClassNameExcludeMatcher(), getMethodNameMatcher()); // 注册通知监听器 process.register(listener, enhancer); effect = enhancer.enhance(inst); @@ -159,11 +178,19 @@ public abstract class EnhancerCommand extends AnnotatedCommand { // no class effected // might be method code too large process.appendResult(new EnhancerModel(effect, false, "No class or method is affected")); + + String smCommand = Ansi.ansi().fg(Ansi.Color.GREEN).a("sm CLASS_NAME METHOD_NAME").reset().toString(); + String optionsCommand = Ansi.ansi().fg(Ansi.Color.GREEN).a("options unsafe true").reset().toString(); + String javaPackage = Ansi.ansi().fg(Ansi.Color.GREEN).a("java.*").reset().toString(); + String resetCommand = Ansi.ansi().fg(Ansi.Color.GREEN).a("reset CLASS_NAME").reset().toString(); + String logStr = Ansi.ansi().fg(Ansi.Color.GREEN).a(LogUtil.loggingFile()).reset().toString(); + String issueStr = Ansi.ansi().fg(Ansi.Color.GREEN).a("https://github.com/alibaba/arthas/issues/47").reset().toString(); String msg = "No class or method is affected, try:\n" - + "1. sm CLASS_NAME METHOD_NAME to make sure the method you are tracing actually exists (it might be in your parent class).\n" - + "2. reset CLASS_NAME and try again, your method body might be too large.\n" - + "3. check arthas log: " + LogUtil.loggingFile() + "\n" - + "4. visit https://github.com/alibaba/arthas/issues/47 for more details."; + + "1. Execute `" + smCommand + "` to make sure the method you are tracing actually exists (it might be in your parent class).\n" + + "2. Execute `" + optionsCommand + "`, if you want to enhance the classes under the `" + javaPackage + "` package.\n" + + "3. Execute `" + resetCommand + "` and try again, your method body might be too large.\n" + + "4. Check arthas log: " + logStr + "\n" + + "5. Visit " + issueStr + " for more details."; process.end(-1, msg); return; } @@ -194,4 +221,8 @@ public abstract class EnhancerCommand extends AnnotatedCommand { protected void completeArgument3(Completion completion) { super.complete(completion); } + + public String getExcludeClassPattern() { + return excludeClassPattern; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/GroovyScriptCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/GroovyScriptCommand.java index 2abd721ec..5090785dd 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/GroovyScriptCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/GroovyScriptCommand.java @@ -79,6 +79,11 @@ public class GroovyScriptCommand extends EnhancerCommand implements ScriptSuppor throw new UnsupportedOperationException("groovy command is not supported yet!"); } + @Override + protected Matcher getClassNameExcludeMatcher() { + throw new UnsupportedOperationException("groovy command is not supported yet!"); + } + @Override protected Matcher getMethodNameMatcher() { throw new UnsupportedOperationException("groovy command is not supported yet!"); diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java index 44eaeafd6..2e8dd4d51 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java @@ -115,6 +115,9 @@ public class JvmCommand extends AnnotatedCommand { } private void addCompilation(JvmModel jvmModel) { + if (compilationMXBean == null) { + return; + } String group = "COMPILATION"; jvmModel.addItem(group, "NAME", compilationMXBean.getName()); if (compilationMXBean.isCompilationTimeMonitoringSupported()) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorCommand.java index 2184a4d0f..edad1078c 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorCommand.java @@ -115,6 +115,14 @@ public class MonitorCommand extends EnhancerCommand { return classNameMatcher; } + @Override + protected Matcher getClassNameExcludeMatcher() { + if (classNameExcludeMatcher == null && getExcludeClassPattern() != null) { + classNameExcludeMatcher = SearchUtils.classNameMatcher(getExcludeClassPattern(), isRegEx()); + } + return classNameExcludeMatcher; + } + @Override protected Matcher getMethodNameMatcher() { if (methodNameMatcher == null) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java index e12f2266d..6e38585a7 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java @@ -125,8 +125,10 @@ public class ProfilerCommand extends AnnotatedCommand { } if (OSUtils.isLinux()) { profierSoPath = "async-profiler/libasyncProfiler-linux-x64.so"; - if (OSUtils.isArm()) { + if (OSUtils.isArm32()) { profierSoPath = "async-profiler/libasyncProfiler-linux-arm.so"; + } else if (OSUtils.isArm64()) { + profierSoPath = "async-profiler/libasyncProfiler-linux-aarch64.so"; } } @@ -431,10 +433,16 @@ public class ProfilerCommand extends AnnotatedCommand { return profilerModel; } - private String outputFile() { + private String outputFile() throws IOException { if (this.file == null) { - this.file = new File("arthas-output", - new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + "." + this.format).getAbsolutePath(); + File outputPath = ArthasBootstrap.getInstance().getOutputPath(); + if (outputPath != null) { + this.file = new File(outputPath, + new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()) + "." + this.format) + .getAbsolutePath(); + } else { + this.file = File.createTempFile("arthas-output", "." + this.format).getAbsolutePath(); + } } return file; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java index 88855d72c..478425b5e 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java @@ -19,7 +19,6 @@ import java.util.Date; public class StackAdviceListener extends AdviceListenerAdapter { private static final Logger logger = LoggerFactory.getLogger(StackAdviceListener.class); - private final ThreadLocal stackThreadLocal = new ThreadLocal(); private final ThreadLocalWatch threadLocalWatch = new ThreadLocalWatch(); private StackCommand command; private CommandProcess process; @@ -33,7 +32,6 @@ public class StackAdviceListener extends AdviceListenerAdapter { @Override public void before(ClassLoader loader, Class clazz, ArthasMethod method, Object target, Object[] args) throws Throwable { - stackThreadLocal.set(ThreadUtil.getThreadStackModel(loader, Thread.currentThread())); // 开始计算本次方法调用耗时 threadLocalWatch.start(); } @@ -62,8 +60,7 @@ public class StackAdviceListener extends AdviceListenerAdapter { } if (conditionResult) { // TODO: concurrency issues for process.write - // TODO: should clear stackThreadLocal? - StackModel stackModel = stackThreadLocal.get(); + StackModel stackModel = ThreadUtil.getThreadStackModel(advice.getLoader(), Thread.currentThread()); stackModel.setTs(new Date()); process.appendResult(stackModel); process.times().incrementAndGet(); diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackCommand.java index d5a721860..985ae5e6c 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackCommand.java @@ -93,6 +93,14 @@ public class StackCommand extends EnhancerCommand { return classNameMatcher; } + @Override + protected Matcher getClassNameExcludeMatcher() { + if (classNameExcludeMatcher == null && getExcludeClassPattern() != null) { + classNameExcludeMatcher = SearchUtils.classNameMatcher(getExcludeClassPattern(), isRegEx()); + } + return classNameExcludeMatcher; + } + @Override protected Matcher getMethodNameMatcher() { if (methodNameMatcher == null) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java index 21321ecde..63e975174 100755 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ThreadCommand.java @@ -129,7 +129,7 @@ public class ThreadCommand extends AnnotatedCommand { } private ExitStatus processAllThreads(CommandProcess process) { - Map threads = ThreadUtil.getThreads(); + List threads = ThreadUtil.getThreads(); // 统计各种线程状态 Map stateCountMap = new LinkedHashMap(); @@ -137,7 +137,7 @@ public class ThreadCommand extends AnnotatedCommand { stateCountMap.put(s, 0); } - for (ThreadVO thread : threads.values()) { + for (ThreadVO thread : threads) { State threadState = thread.getState(); Integer count = stateCountMap.get(threadState); stateCountMap.put(threadState, count + 1); @@ -149,7 +149,7 @@ public class ThreadCommand extends AnnotatedCommand { this.state = this.state.toUpperCase(); if (states.contains(this.state)) { includeInternalThreads = false; - for (ThreadVO thread : threads.values()) { + for (ThreadVO thread : threads) { if (thread.getState() != null && state.equals(thread.getState().name())) { resultThreads.add(thread); } @@ -158,7 +158,7 @@ public class ThreadCommand extends AnnotatedCommand { return ExitStatus.failure(1, "Illegal argument, state should be one of " + states); } } else { - resultThreads = threads.values(); + resultThreads = threads; } //thread stats @@ -183,12 +183,19 @@ public class ThreadCommand extends AnnotatedCommand { private ExitStatus processTopBusyThreads(CommandProcess process) { ThreadSampler threadSampler = new ThreadSampler(); - threadSampler.sample(ThreadUtil.getThreads().values()); + threadSampler.sample(ThreadUtil.getThreads()); threadSampler.pause(sampleInterval); - List threadStats = threadSampler.sample(ThreadUtil.getThreads().values()); + List threadStats = threadSampler.sample(ThreadUtil.getThreads()); int limit = Math.min(threadStats.size(), topNBusy); - List topNThreads = threadStats.subList(0, limit); + + List topNThreads = null; + if (limit > 0) { + topNThreads = threadStats.subList(0, limit); + } else { // -1 for all threads + topNThreads = threadStats; + } + List tids = new ArrayList(topNThreads.size()); for (ThreadVO thread : topNThreads) { if (thread.getId() > 0) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java index bc845b385..e1c914585 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java @@ -306,6 +306,14 @@ public class TimeTunnelCommand extends EnhancerCommand { return classNameMatcher; } + @Override + protected Matcher getClassNameExcludeMatcher() { + if (classNameExcludeMatcher == null && getExcludeClassPattern() != null) { + classNameExcludeMatcher = SearchUtils.classNameMatcher(getExcludeClassPattern(), isRegEx()); + } + return classNameExcludeMatcher; + } + @Override protected Matcher getMethodNameMatcher() { if (methodNameMatcher == null) { @@ -355,8 +363,8 @@ public class TimeTunnelCommand extends EnhancerCommand { } Advice advice = tf.getAdvice(); - Object value = ExpressFactory.threadLocalExpress(advice).get(watchExpress); + Object value = ExpressFactory.unpooledExpress(advice.getLoader()).bind(advice).get(watchExpress); TimeTunnelModel timeTunnelModel = new TimeTunnelModel() .setWatchValue(getExpandObject(value)) .setExpand(expand) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceCommand.java index 849b7682f..ae227d744 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceCommand.java @@ -38,6 +38,7 @@ import java.util.List; " trace -E com.test.ClassA|org.test.ClassB method1|method2|method3\n" + " trace demo.MathGame run -n 5\n" + " trace demo.MathGame run --skipJDKMethod false\n" + + " trace javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter\n" + Constants.WIKI + Constants.WIKI_HOME + "trace") //@formatter:on public class TraceCommand extends EnhancerCommand { @@ -133,6 +134,14 @@ public class TraceCommand extends EnhancerCommand { return classNameMatcher; } + @Override + protected Matcher getClassNameExcludeMatcher() { + if (classNameExcludeMatcher == null && getExcludeClassPattern() != null) { + classNameExcludeMatcher = SearchUtils.classNameMatcher(getExcludeClassPattern(), isRegEx()); + } + return classNameExcludeMatcher; + } + @Override protected Matcher getMethodNameMatcher() { if (methodNameMatcher == null) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceEntity.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceEntity.java index c2e1ecbf9..3cc2a4b5a 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceEntity.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TraceEntity.java @@ -18,14 +18,6 @@ public class TraceEntity { this.deep = 0; } - public int getDeep() { - return deep; - } - - public void setDeep(int deep) { - this.deep = deep; - } - private TraceTree createTraceTree(ClassLoader loader) { return new TraceTree(ThreadUtil.getThreadNode(loader, Thread.currentThread())); } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java new file mode 100644 index 000000000..0a8669b56 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java @@ -0,0 +1,321 @@ +package com.taobao.arthas.core.command.monitor200; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.lang.instrument.Instrumentation; +import java.security.CodeSource; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.IOUtils; +import com.taobao.arthas.common.VmToolUtils; +import com.taobao.arthas.core.command.Constants; +import com.taobao.arthas.core.command.express.Express; +import com.taobao.arthas.core.command.express.ExpressException; +import com.taobao.arthas.core.command.express.ExpressFactory; +import com.taobao.arthas.core.command.model.ClassLoaderVO; +import com.taobao.arthas.core.command.model.SearchClassModel; +import com.taobao.arthas.core.shell.cli.Completion; +import com.taobao.arthas.core.shell.cli.CompletionUtils; +import com.taobao.arthas.core.shell.cli.OptionCompleteHandler; +import com.taobao.arthas.core.shell.command.AnnotatedCommand; +import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.arthas.core.util.ClassLoaderUtils; +import com.taobao.arthas.core.util.ClassUtils; +import com.taobao.arthas.core.util.SearchUtils; +import com.taobao.arthas.core.view.ObjectView; +import com.taobao.middleware.cli.annotations.DefaultValue; +import com.taobao.middleware.cli.annotations.Description; +import com.taobao.middleware.cli.annotations.Name; +import com.taobao.middleware.cli.annotations.Option; +import com.taobao.middleware.cli.annotations.Summary; + +import arthas.VmTool; + +/** + * + * @author hengyunabc 2021-04-27 + * @author ZhangZiCheng 2021-04-29 + * + */ +//@formatter:off +@Name("vmtool") +@Summary("jvm tool") +@Description(Constants.EXAMPLE + + " vmtool --action getInstances --className demo.MathGame\n" + + " vmtool --action getInstances --className demo.MathGame --express 'instances.length'\n" + + " vmtool --action getInstances --className demo.MathGame --express 'instances[0]'\n" + + " vmtool --action getInstances --className demo.MathGame -x 2\n" + + " vmtool --action getInstances --className java.lang.String --limit 10\n" + + " vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext\n" + + " vmtool --action forceGc\n" + + Constants.WIKI + Constants.WIKI_HOME + "vmtool") +//@formatter:on +public class VmToolCommand extends AnnotatedCommand { + private static final Logger logger = LoggerFactory.getLogger(VmToolCommand.class); + + private VmToolAction action; + private String className; + private String express; + + private String hashCode = null; + private String classLoaderClass; + /** + * default value 1 + */ + private int expand; + + /** + * default value 10 + */ + private int limit; + + private String libPath; + private static String defaultLibPath; + private static VmTool vmTool = null; + + static { + String libName = VmToolUtils.detectLibName(); + if (libName != null) { + CodeSource codeSource = VmToolCommand.class.getProtectionDomain().getCodeSource(); + if (codeSource != null) { + try { + File bootJarPath = new File(codeSource.getLocation().toURI().getSchemeSpecificPart()); + File soFile = new File(bootJarPath.getParentFile(), "lib" + File.separator + libName); + if (soFile.exists()) { + defaultLibPath = soFile.getAbsolutePath(); + } + } catch (Throwable e) { + logger.error("can not find VmTool so", e); + } + } + } + + } + + @Option(shortName = "a", longName = "action", required = true) + @Description("Action to execute") + public void setAction(VmToolAction action) { + this.action = action; + } + + @Option(longName = "className") + @Description("The class name") + public void setClassName(String className) { + this.className = className; + } + + @Option(shortName = "x", longName = "expand") + @Description("Expand level of object (1 by default)") + @DefaultValue("1") + public void setExpand(int expand) { + this.expand = expand; + } + + @Option(shortName = "c", longName = "classloader") + @Description("The hash code of the special class's classLoader") + public void setHashCode(String hashCode) { + this.hashCode = hashCode; + } + + @Option(longName = "classLoaderClass") + @Description("The class name of the special class's classLoader.") + public void setClassLoaderClass(String classLoaderClass) { + this.classLoaderClass = classLoaderClass; + } + + @Option(shortName = "l", longName = "limit") + @Description("Set the limit value of the getInstances action, default value is 10, set to -1 is unlimited") + @DefaultValue("10") + public void setLimit(int limit) { + this.limit = limit; + } + + @Option(longName = "libPath") + @Description("The specify lib path.") + public void setLibPath(String path) { + libPath = path; + } + + @Option(longName = "express", required = false) + @Description("The ognl expression, default valueis `instances`.") + public void setExpress(String express) { + this.express = express; + } + + public enum VmToolAction { + getInstances, forceGc + } + + @Override + public void process(final CommandProcess process) { + try { + Instrumentation inst = process.session().getInstrumentation(); + + if (VmToolAction.getInstances.equals(action)) { + if (className == null) { + process.end(-1, "The className option cannot be empty!"); + return; + } + ClassLoader classLoader = ClassLoader.getSystemClassLoader(); + if (hashCode == null && classLoaderClass != null) { + List matchedClassLoaders = ClassLoaderUtils.getClassLoaderByClassName(inst, + classLoaderClass); + if (matchedClassLoaders.size() == 1) { + classLoader = matchedClassLoaders.get(0); + hashCode = Integer.toHexString(matchedClassLoaders.get(0).hashCode()); + } else if (matchedClassLoaders.size() > 1) { + Collection classLoaderVOList = ClassUtils + .createClassLoaderVOList(matchedClassLoaders); + SearchClassModel searchclassModel = new SearchClassModel().setClassLoaderClass(classLoaderClass) + .setMatchedClassLoaders(classLoaderVOList); + process.appendResult(searchclassModel); + process.end(-1, + "Found more than one classloader by class name, please specify classloader with '-c '"); + return; + } else { + process.end(-1, "Can not find classloader by class name: " + classLoaderClass + "."); + return; + } + } + + List> matchedClasses = new ArrayList>( + SearchUtils.searchClassOnly(inst, className, false, hashCode)); + int matchedClassSize = matchedClasses.size(); + if (matchedClassSize == 0) { + process.end(-1, "Can not find class by class name: " + className + "."); + return; + } else if (matchedClassSize > 1) { + process.end(-1, "Found more than one class: " + matchedClasses + ", please specify classloader with '-c '"); + return; + } else { + Object[] instances = vmToolInstance().getInstances(matchedClasses.get(0), limit); + Object value = instances; + if (express != null) { + Express unpooledExpress = ExpressFactory.unpooledExpress(classLoader); + try { + value = unpooledExpress.bind(new InstancesWrapper(instances)).get(express); + } catch (ExpressException e) { + logger.warn("ognl: failed execute express: " + express, e); + process.end(-1, "Failed to execute ognl, exception message: " + e.getMessage() + + ", please check $HOME/logs/arthas/arthas.log for more details. "); + } + } + + process.write(new ObjectView(value, this.expand).draw()); + process.write("\n"); + process.end(); + } + } else if (VmToolAction.forceGc.equals(action)) { + vmToolInstance().forceGc(); + process.write("\n"); + process.end(); + return; + } + + process.end(); + } catch (Throwable e) { + logger.error("vmtool error", e); + process.end(1, "vmtool error: " + e.getMessage()); + } + } + + static class InstancesWrapper { + Object instances; + + public InstancesWrapper(Object instances) { + this.instances = instances; + } + + public Object getInstances() { + return instances; + } + + public void setInstances(Object instances) { + this.instances = instances; + } + } + + private VmTool vmToolInstance() { + if (vmTool != null) { + return vmTool; + } else { + if (libPath == null) { + libPath = defaultLibPath; + } + + // 尝试把lib文件复制到临时文件里,避免多次attach时出现 Native Library already loaded in another classloader + FileOutputStream tmpLibOutputStream = null; + FileInputStream libInputStream = null; + try { + File tmpLibFile = File.createTempFile(VmTool.JNI_LIBRARY_NAME, null); + tmpLibOutputStream = new FileOutputStream(tmpLibFile); + libInputStream = new FileInputStream(new File(libPath)); + + IOUtils.copy(libInputStream, tmpLibOutputStream); + libPath = tmpLibFile.getAbsolutePath(); + logger.debug("copy {} to {}", libPath, tmpLibFile); + } catch (Throwable e) { + logger.error("try to copy lib error! libPath: {}", libPath, e); + } finally { + IOUtils.close(libInputStream); + IOUtils.close(tmpLibOutputStream); + } + + vmTool = VmTool.getInstance(libPath); + } + return vmTool; + } + + private Set actions() { + Set values = new HashSet(); + for (VmToolAction action : VmToolAction.values()) { + values.add(action.toString()); + } + return values; + } + + @Override + public void complete(Completion completion) { + List handlers = new ArrayList(); + + handlers.add(new OptionCompleteHandler() { + + @Override + public boolean matchName(String token) { + return "-a".equals(token) || "--action".equals(token); + } + + @Override + public boolean complete(Completion completion) { + return CompletionUtils.complete(completion, actions()); + } + + }); + + handlers.add(new OptionCompleteHandler() { + @Override + public boolean matchName(String token) { + return "--className".equals(token); + } + + @Override + public boolean complete(Completion completion) { + return CompletionUtils.completeClassName(completion); + } + }); + + if (CompletionUtils.completeOptions(completion, handlers)) { + return; + } + + super.complete(completion); + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java index 36b8590f5..6519ca3cd 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java @@ -2,6 +2,7 @@ package com.taobao.arthas.core.command.monitor200; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.core.advisor.AccessPoint; import com.taobao.arthas.core.advisor.Advice; import com.taobao.arthas.core.advisor.AdviceListenerAdapter; import com.taobao.arthas.core.advisor.ArthasMethod; @@ -72,7 +73,6 @@ class WatchAdviceListener extends AdviceListenerAdapter { } - private void watching(Advice advice) { try { // 本次调用的耗时 @@ -83,6 +83,7 @@ class WatchAdviceListener extends AdviceListenerAdapter { } if (conditionResult) { // TODO: concurrency issues for process.write + Object value = getExpressionResult(command.getExpress(), advice, cost); value = ObjectExpandUtils.expand(value, command.getExpand(), command.getSizeLimit()); @@ -92,6 +93,15 @@ class WatchAdviceListener extends AdviceListenerAdapter { model.setValue(value); model.setExpand(command.getExpand()); model.setSizeLimit(command.getSizeLimit()); + model.setClassName(advice.getClazz().getName()); + model.setMethodName(advice.getMethod().getName()); + if (advice.isBefore()) { + model.setAccessPoint(AccessPoint.ACCESS_BEFORE.getKey()); + } else if (advice.isAfterReturning()) { + model.setAccessPoint(AccessPoint.ACCESS_AFTER_RETUNING.getKey()); + } else if (advice.isAfterThrowing()) { + model.setAccessPoint(AccessPoint.ACCESS_AFTER_THROWING.getKey()); + } process.appendResult(model); process.times().incrementAndGet(); @@ -102,8 +112,8 @@ class WatchAdviceListener extends AdviceListenerAdapter { } catch (Throwable e) { logger.warn("watch failed.", e); process.end(-1, "watch failed, condition is: " + command.getConditionExpress() + ", express is: " - + command.getExpress() + ", " + e.getMessage() + ", visit " + LogUtil.loggingFile() - + " for more details."); + + command.getExpress() + ", " + e.getMessage() + ", visit " + LogUtil.loggingFile() + + " for more details."); } } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchCommand.java index 808f93fe2..60b6b0e4b 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchCommand.java @@ -29,6 +29,7 @@ import com.taobao.middleware.cli.annotations.Summary; " watch *StringUtils isBlank params[0] params[0].length==1\n" + " watch *StringUtils isBlank params '#cost>100'\n" + " watch -E -b org\\.apache\\.commons\\.lang\\.StringUtils isBlank params[0]\n" + + " watch javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter\n" + Constants.WIKI + Constants.WIKI_HOME + "watch") public class WatchCommand extends EnhancerCommand { @@ -174,6 +175,14 @@ public class WatchCommand extends EnhancerCommand { return classNameMatcher; } + @Override + protected Matcher getClassNameExcludeMatcher() { + if (classNameExcludeMatcher == null && getExcludeClassPattern() != null) { + classNameExcludeMatcher = SearchUtils.classNameMatcher(getExcludeClassPattern(), isRegEx()); + } + return classNameExcludeMatcher; + } + @Override protected Matcher getMethodNameMatcher() { if (methodNameMatcher == null) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/Base64View.java b/core/src/main/java/com/taobao/arthas/core/command/view/Base64View.java new file mode 100644 index 000000000..e6dee743d --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/view/Base64View.java @@ -0,0 +1,22 @@ +package com.taobao.arthas.core.command.view; + +import com.taobao.arthas.core.command.model.Base64Model; +import com.taobao.arthas.core.shell.command.CommandProcess; + +/** + * + * @author hengyunabc 2021-01-05 + * + */ +public class Base64View extends ResultView { + + @Override + public void draw(CommandProcess process, Base64Model result) { + String content = result.getContent(); + if (content != null) { + process.write(content); + } + process.write("\n"); + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/DashboardView.java b/core/src/main/java/com/taobao/arthas/core/command/view/DashboardView.java index 7a9efa295..5756896c0 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/DashboardView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/DashboardView.java @@ -10,6 +10,7 @@ import com.taobao.text.ui.TableElement; import com.taobao.text.util.RenderUtil; import java.lang.management.MemoryUsage; +import java.util.Date; import java.util.List; import java.util.Map; @@ -155,7 +156,7 @@ public class DashboardView extends ResultView { table.row("java.home", runtimeInfo.getJavaHome()); table.row("systemload.average", String.format("%.2f", runtimeInfo.getSystemLoadAverage())); table.row("processors", "" + runtimeInfo.getProcessors()); - table.row("uptime", "" + runtimeInfo.getUptime() + "s"); + table.row("timestamp/uptime", new Date(runtimeInfo.getTimestamp()).toString() + "/" + runtimeInfo.getUptime() + "s"); return table; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/JadView.java b/core/src/main/java/com/taobao/arthas/core/command/view/JadView.java index 4bcdce113..1a8635efe 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/JadView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/JadView.java @@ -26,19 +26,20 @@ public class JadView extends ResultView { return; } + int width = process.width(); if (result.getMatchedClasses() != null) { Element table = ClassUtils.renderMatchedClasses(result.getMatchedClasses()); - process.write(RenderUtil.render(table)).write("\n"); + process.write(RenderUtil.render(table, width)).write("\n"); } else { ClassVO classInfo = result.getClassInfo(); if (classInfo != null) { process.write("\n"); - process.write(RenderUtil.render(new LabelElement("ClassLoader: ").style(Decoration.bold.fg(Color.red)), process.width())); - process.write(RenderUtil.render(TypeRenderUtils.drawClassLoader(classInfo), process.width()) + "\n"); + process.write(RenderUtil.render(new LabelElement("ClassLoader: ").style(Decoration.bold.fg(Color.red)), width)); + process.write(RenderUtil.render(TypeRenderUtils.drawClassLoader(classInfo), width) + "\n"); } if (result.getLocation() != null) { - process.write(RenderUtil.render(new LabelElement("Location: ").style(Decoration.bold.fg(Color.red)), process.width())); - process.write(RenderUtil.render(new LabelElement(result.getLocation()).style(Decoration.bold.fg(Color.blue)), process.width()) + "\n"); + process.write(RenderUtil.render(new LabelElement("Location: ").style(Decoration.bold.fg(Color.red)), width)); + process.write(RenderUtil.render(new LabelElement(result.getLocation()).style(Decoration.bold.fg(Color.blue)), width) + "\n"); } process.write(LangRenderUtil.render(result.getSource()) + "\n"); process.write(com.taobao.arthas.core.util.Constants.EMPTY_STRING); diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/MBeanView.java b/core/src/main/java/com/taobao/arthas/core/command/view/MBeanView.java index 87349036a..af7feb83c 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/MBeanView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/MBeanView.java @@ -204,7 +204,7 @@ public class MBeanView extends ResultView { table.row(new LabelElement(title).style(Decoration.bold.fg(Color.yellow))); for (String fieldName : fieldNames) { Object fieldValue = descriptor.getFieldValue(fieldName); - table.row(fieldName, fieldValue.toString()); + table.row(fieldName, fieldValue == null ? "" : fieldValue.toString()); } } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/ResultViewResolver.java b/core/src/main/java/com/taobao/arthas/core/command/view/ResultViewResolver.java index 123f464d4..912e15c98 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/ResultViewResolver.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/ResultViewResolver.java @@ -39,6 +39,7 @@ public class ResultViewResolver { //registerView(HistoryView.class); registerView(EchoView.class); registerView(CatView.class); + registerView(Base64View.class); registerView(OptionsView.class); registerView(SystemPropertyView.class); registerView(SystemEnvView.class); @@ -56,6 +57,7 @@ public class ResultViewResolver { registerView(MemoryCompilerView.class); registerView(OgnlView.class); registerView(RedefineView.class); + registerView(RetransformView.class); registerView(SearchClassView.class); registerView(SearchMethodView.class); diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/RetransformView.java b/core/src/main/java/com/taobao/arthas/core/command/view/RetransformView.java new file mode 100644 index 000000000..5f64f1679 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/command/view/RetransformView.java @@ -0,0 +1,63 @@ +package com.taobao.arthas.core.command.view; + +import com.taobao.arthas.core.command.klass100.RetransformCommand.RetransformEntry; +import com.taobao.arthas.core.command.model.RetransformModel; +import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.text.Decoration; +import com.taobao.text.ui.RowElement; +import com.taobao.text.ui.TableElement; +import com.taobao.text.util.RenderUtil; + +/** + * + * @author hengyunabc 2021-01-06 + * + */ +public class RetransformView extends ResultView { + + @Override + public void draw(CommandProcess process, RetransformModel result) { + // 匹配到多个 classloader + if (result.getMatchedClassLoaders() != null) { + process.write("Matched classloaders: \n"); + ClassLoaderView.drawClassLoaders(process, result.getMatchedClassLoaders(), false); + process.write("\n"); + return; + } + + // retransform -d + if (result.getDeletedRetransformEntry() != null) { + process.write("Delete RetransformEntry by id success. id: " + result.getDeletedRetransformEntry().getId()); + process.write("\n"); + return; + } + + // retransform -l + if (result.getRetransformEntries() != null) { + // header + TableElement table = new TableElement(1, 1, 1, 1, 1).rightCellPadding(1); + table.add(new RowElement().style(Decoration.bold.bold()).add("Id", "ClassName", "TransformCount", "LoaderHash", + "LoaderClassName")); + + for (RetransformEntry entry : result.getRetransformEntries()) { + table.row("" + entry.getId(), "" + entry.getClassName(), "" + entry.getTransformCount(), "" + entry.getHashCode(), + "" + entry.getClassLoaderClass()); + } + + process.write(RenderUtil.render(table)); + return; + } + + // retransform /tmp/Demo.class + if (result.getRetransformClasses() != null) { + StringBuilder sb = new StringBuilder(); + for (String aClass : result.getRetransformClasses()) { + sb.append(aClass).append("\n"); + } + process.write("retransform success, size: " + result.getRetransformCount()).write(", classes:\n") + .write(sb.toString()); + } + + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/SessionView.java b/core/src/main/java/com/taobao/arthas/core/command/view/SessionView.java index 9f55fceb5..c496df9d7 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/SessionView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/SessionView.java @@ -26,6 +26,7 @@ public class SessionView extends ResultView { } if (result.getTunnelServer() != null) { table.row("TUNNEL_SERVER", "" + result.getTunnelServer()); + table.row("TUNNEL_CONNECTED", "" + result.isTunnelConnected()); } if (result.getStatUrl() != null) { table.row("STAT_URL", result.getStatUrl()); diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/ViewRenderUtil.java b/core/src/main/java/com/taobao/arthas/core/command/view/ViewRenderUtil.java index 55e5b9743..a7799c1ac 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/ViewRenderUtil.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/ViewRenderUtil.java @@ -123,6 +123,7 @@ public class ViewRenderUtil { ) ); + int count = 0; for (ThreadVO thread : threads) { Color color = colorMapping.get(thread.getState()); String time = formatTimeMills(thread.getTime()); @@ -151,6 +152,9 @@ public class ViewRenderUtil { new LabelElement(thread.isInterrupted()), daemonLabel ); + if (++count >= height) { + break; + } } return RenderUtil.render(table, width, height); } @@ -159,13 +163,33 @@ public class ViewRenderUtil { long seconds = timeMills / 1000; long mills = timeMills % 1000; long min = seconds / 60; - //return min + ":" + (seconds % 60); - return String.format("%d:%d.%03d", min, seconds, mills); + seconds = seconds % 60; + + //return String.format("%d:%d.%03d", min, seconds, mills); + String str; + if (mills >= 100) { + str = min + ":" + seconds + "." + mills; + } else if (mills >= 10) { + str = min + ":" + seconds + ".0" + mills; + } else { + str = min + ":" + seconds + ".00" + mills; + } + return str; } private static String formatTimeMillsToSeconds(long timeMills) { long seconds = timeMills / 1000; long mills = timeMills % 1000; - return String.format("%d.%03d", seconds, mills); + + //return String.format("%d.%03d", seconds, mills); + String str; + if (mills >= 100) { + str = seconds + "." + mills; + } else if (mills >= 10) { + str = seconds + ".0" + mills; + } else { + str = seconds + ".00" + mills; + } + return str; } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java b/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java index 981ceb73a..920c7e30a 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java @@ -15,6 +15,7 @@ public class WatchView extends ResultView { @Override public void draw(CommandProcess process, WatchModel model) { String result = ObjectExpandUtils.toString(model.getValue()); + process.write("method=" + model.getClassName() + "." + model.getMethodName() + " location=" + model.getAccessPoint() + "\n"); process.write("ts=" + DateUtils.formatDate(model.getTs()) + "; [cost=" + model.getCost() + "ms] result=" + result + "\n"); } diff --git a/core/src/main/java/com/taobao/arthas/core/config/Configure.java b/core/src/main/java/com/taobao/arthas/core/config/Configure.java index 17a62d868..433b22131 100644 --- a/core/src/main/java/com/taobao/arthas/core/config/Configure.java +++ b/core/src/main/java/com/taobao/arthas/core/config/Configure.java @@ -17,17 +17,38 @@ import static java.lang.reflect.Modifier.isStatic; */ @Config(prefix = "arthas") public class Configure { - public static final long DEFAULT_SESSION_TIMEOUT_SECONDS = ShellServerOptions.DEFAULT_SESSION_TIMEOUT/1000; + private String ip; - private int telnetPort; - private int httpPort; - private long javaPid; + private Integer telnetPort; + private Integer httpPort; + private Long javaPid; private String arthasCore; private String arthasAgent; private String tunnelServer; private String agentId; + private String username; + private String password; + + /** + * @see com.taobao.arthas.common.ArthasConstants#ARTHAS_OUTPUT + */ + private String outputPath; + + /** + * 需要被增强的ClassLoader的全类名,多个用英文 , 分隔 + */ + private String enhanceLoaders; + + /** + *
+     * 1. 如果显式传入 arthas.agentId ,则直接使用
+     * 2. 如果用户没有指定,则自动尝试在查找应用的 appname,加为前缀,比如 system properties设置 project.name是 demo,则
+     *    生成的 agentId是  demo-xxxx
+     * 
+ */ + private String appName; /** * report executed command */ @@ -35,8 +56,14 @@ public class Configure { /** * session timeout seconds + * @see ShellServerOptions#DEFAULT_SESSION_TIMEOUT */ - private long sessionTimeout = DEFAULT_SESSION_TIMEOUT_SECONDS; + private Long sessionTimeout; + + /** + * disabled commands + */ + private String disabledCommands; public String getIp() { return ip; @@ -46,7 +73,7 @@ public class Configure { this.ip = ip; } - public int getTelnetPort() { + public Integer getTelnetPort() { return telnetPort; } @@ -58,7 +85,7 @@ public class Configure { this.httpPort = httpPort; } - public int getHttpPort() { + public Integer getHttpPort() { return httpPort; } @@ -86,7 +113,7 @@ public class Configure { this.arthasCore = arthasCore; } - public long getSessionTimeout() { + public Long getSessionTimeout() { return sessionTimeout; } @@ -118,6 +145,54 @@ public class Configure { this.statUrl = statUrl; } + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getEnhanceLoaders() { + return enhanceLoaders; + } + + public void setEnhanceLoaders(String enhanceLoaders) { + this.enhanceLoaders = enhanceLoaders; + } + + public String getOutputPath() { + return outputPath; + } + + public void setOutputPath(String outputPath) { + this.outputPath = outputPath; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getDisabledCommands() { + return disabledCommands; + } + + public void setDisabledCommands(String disabledCommands) { + this.disabledCommands = disabledCommands; + } + /** * 序列化成字符串 * diff --git a/core/src/main/java/com/taobao/arthas/core/config/SecondConfig.java b/core/src/main/java/com/taobao/arthas/core/config/SecondConfig.java deleted file mode 100644 index 013a45790..000000000 --- a/core/src/main/java/com/taobao/arthas/core/config/SecondConfig.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.taobao.arthas.core.config; - -public class SecondConfig { - -} diff --git a/core/src/main/java/com/taobao/arthas/core/env/MutablePropertySources.java b/core/src/main/java/com/taobao/arthas/core/env/MutablePropertySources.java index 909a70ee5..3a71b7dc1 100644 --- a/core/src/main/java/com/taobao/arthas/core/env/MutablePropertySources.java +++ b/core/src/main/java/com/taobao/arthas/core/env/MutablePropertySources.java @@ -195,9 +195,7 @@ public class MutablePropertySources implements PropertySources { * Remove the given property source if it is present. */ protected void removeIfPresent(PropertySource propertySource) { - if (this.propertySourceList.contains(propertySource)) { - this.propertySourceList.remove(propertySource); - } + this.propertySourceList.remove(propertySource); } /** diff --git a/core/src/main/java/com/taobao/arthas/core/security/BasicPrincipal.java b/core/src/main/java/com/taobao/arthas/core/security/BasicPrincipal.java new file mode 100644 index 000000000..327047513 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/security/BasicPrincipal.java @@ -0,0 +1,69 @@ +package com.taobao.arthas.core.security; + +import java.security.Principal; + +/** + * Basic {@link Principal}. + * + * @author hengyunabc 2021-03-04 + */ +public final class BasicPrincipal implements Principal { + + private final String username; + private final String password; + + public BasicPrincipal(String username, String password) { + this.username = username; + this.password = password; + } + + @Override + public String getName() { + return username; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BasicPrincipal other = (BasicPrincipal) obj; + if (password == null) { + if (other.password != null) + return false; + } else if (!password.equals(other.password)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + // do not display the password + return "BasicPrincipal[" + username + "]"; + } +} \ No newline at end of file diff --git a/core/src/main/java/com/taobao/arthas/core/security/SecurityAuthenticator.java b/core/src/main/java/com/taobao/arthas/core/security/SecurityAuthenticator.java new file mode 100644 index 000000000..598c31980 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/security/SecurityAuthenticator.java @@ -0,0 +1,71 @@ +package com.taobao.arthas.core.security; + +import java.security.Principal; + +import javax.security.auth.Subject; +import javax.security.auth.login.LoginException; + +/** + * A {@link SecurityAuthenticator} allows to plugin custom authenticators, such + * as JAAS based or custom implementations. + */ +public interface SecurityAuthenticator { + + + boolean needLogin(); + + /** + * Sets the name of the realm to use. + */ + void setName(String name); + + /** + * Gets the name of the realm. + */ + String getName(); + + /** + * Sets the role class names (separated by comma) + *

+ * By default if no explicit role class names has been configured, then this + * implementation will assume the {@link Subject} + * {@link java.security.Principal}s is a role if the classname contains the word + * role (lower cased). + * + * @param names a list of FQN class names for role + * {@link java.security.Principal} implementations. + */ + void setRoleClassNames(String names); + + /** + * Attempts to login the {@link java.security.Principal} on this realm. + *

+ * The login is a success if no Exception is thrown, and a {@link Subject} is + * returned. + * + * @param principal the principal + * @return the subject for the logged in principal, must not be + * null + * @throws LoginException is thrown if error logging in the + * {@link java.security.Principal} + */ + Subject login(Principal principal) throws LoginException; + + /** + * Attempt to logout the subject. + * + * @param subject subject to logout + * @throws LoginException is thrown if error logging out subject + */ + void logout(Subject subject) throws LoginException; + + /** + * Gets the user roles from the given {@link Subject} + * + * @param subject the subject + * @return null if no roles, otherwise a String with roles separated by + * comma. + */ + String getUserRoles(Subject subject); + +} \ No newline at end of file diff --git a/core/src/main/java/com/taobao/arthas/core/security/SecurityAuthenticatorImpl.java b/core/src/main/java/com/taobao/arthas/core/security/SecurityAuthenticatorImpl.java new file mode 100644 index 000000000..e43bd19d8 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/security/SecurityAuthenticatorImpl.java @@ -0,0 +1,90 @@ +package com.taobao.arthas.core.security; + +import java.security.Principal; + +import javax.security.auth.Subject; +import javax.security.auth.login.LoginException; + +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.util.StringUtils; + +/** + * TODO 支持不同角色不同权限,command按角色分类? + * + * @author hengyunabc 2021-03-03 + * + */ +public class SecurityAuthenticatorImpl implements SecurityAuthenticator { + private static final Logger logger = LoggerFactory.getLogger(SecurityAuthenticatorImpl.class); + private String username; + private String password; + private Subject subject; + + public SecurityAuthenticatorImpl(String username, String password) { + if (username != null && password == null) { + password = StringUtils.randomString(32); + logger.info("\nUsing generated security password: {}\n", password); + } + if (username == null && password != null) { + username = ArthasConstants.DEFAULT_USERNAME; + } + + this.username = username; + this.password = password; + + subject = new Subject(); + } + + @Override + public void setName(String name) { + // TODO Auto-generated method stub + + } + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setRoleClassNames(String names) { + // TODO Auto-generated method stub + + } + + @Override + public Subject login(Principal principal) throws LoginException { + if (principal == null) { + return null; + } + if (principal instanceof BasicPrincipal) { + BasicPrincipal basicPrincipal = (BasicPrincipal) principal; + if (basicPrincipal.getName().equals(username) && basicPrincipal.getPassword().equals(this.password)) { + return subject; + } + } + + return null; + } + + @Override + public void logout(Subject subject) throws LoginException { + // TODO Auto-generated method stub + + } + + @Override + public String getUserRoles(Subject subject) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean needLogin() { + return username != null && password != null; + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/server/ArthasBootstrap.java b/core/src/main/java/com/taobao/arthas/core/server/ArthasBootstrap.java index 108965b2b..2ffd72bac 100644 --- a/core/src/main/java/com/taobao/arthas/core/server/ArthasBootstrap.java +++ b/core/src/main/java/com/taobao/arthas/core/server/ArthasBootstrap.java @@ -9,10 +9,12 @@ import java.lang.reflect.Method; import java.security.CodeSource; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import java.util.Set; import java.util.Timer; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -25,7 +27,16 @@ import com.alibaba.arthas.deps.ch.qos.logback.classic.LoggerContext; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; import com.alibaba.arthas.tunnel.client.TunnelClient; +import com.alibaba.bytekit.asm.instrument.InstrumentConfig; +import com.alibaba.bytekit.asm.instrument.InstrumentParseResult; +import com.alibaba.bytekit.asm.instrument.InstrumentTransformer; +import com.alibaba.bytekit.asm.matcher.SimpleClassMatcher; +import com.alibaba.bytekit.utils.AsmUtils; +import com.alibaba.bytekit.utils.IOUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; import com.taobao.arthas.common.AnsiLog; +import com.taobao.arthas.common.ArthasConstants; import com.taobao.arthas.common.PidUtils; import com.taobao.arthas.common.SocketUtils; import com.taobao.arthas.core.advisor.Enhancer; @@ -39,6 +50,9 @@ import com.taobao.arthas.core.env.ArthasEnvironment; import com.taobao.arthas.core.env.MapPropertySource; import com.taobao.arthas.core.env.PropertiesPropertySource; import com.taobao.arthas.core.env.PropertySource; +import com.taobao.arthas.core.security.SecurityAuthenticator; +import com.taobao.arthas.core.security.SecurityAuthenticatorImpl; +import com.taobao.arthas.core.server.instrument.ClassLoader_Instrument; import com.taobao.arthas.core.shell.ShellServer; import com.taobao.arthas.core.shell.ShellServerOptions; import com.taobao.arthas.core.shell.command.CommandResolver; @@ -50,10 +64,13 @@ import com.taobao.arthas.core.shell.session.SessionManager; import com.taobao.arthas.core.shell.session.impl.SessionManagerImpl; import com.taobao.arthas.core.shell.term.impl.HttpTermServer; import com.taobao.arthas.core.shell.term.impl.http.api.HttpApiHandler; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; import com.taobao.arthas.core.shell.term.impl.httptelnet.HttpTelnetTermServer; import com.taobao.arthas.core.util.ArthasBanner; import com.taobao.arthas.core.util.FileUtils; +import com.taobao.arthas.core.util.InstrumentationUtils; import com.taobao.arthas.core.util.LogUtil; +import com.taobao.arthas.core.util.StringUtils; import com.taobao.arthas.core.util.UserStatUtil; import com.taobao.arthas.core.util.affect.EnhancerAffect; import com.taobao.arthas.core.util.matcher.WildcardMatcher; @@ -84,13 +101,14 @@ public class ArthasBootstrap { private AtomicBoolean isBindRef = new AtomicBoolean(false); private Instrumentation instrumentation; + private InstrumentTransformer classLoaderInstrumentTransformer; private Thread shutdown; private ShellServer shellServer; private ScheduledExecutorService executorService; private SessionManager sessionManager; private TunnelClient tunnelClient; - private File arthasOutputDir; + private File outputPath; private static LoggerContext loggerContext; private EventExecutorGroup workerGroup; @@ -105,24 +123,35 @@ public class ArthasBootstrap { private HttpApiHandler httpApiHandler; + private HttpSessionManager httpSessionManager; + private SecurityAuthenticator securityAuthenticator; + private ArthasBootstrap(Instrumentation instrumentation, Map args) throws Throwable { this.instrumentation = instrumentation; - String outputPath = System.getProperty("arthas.output.dir", "arthas-output"); - arthasOutputDir = new File(outputPath); - arthasOutputDir.mkdirs(); + initFastjson(); // 1. initSpy() - initSpy(instrumentation); + initSpy(); // 2. ArthasEnvironment initArthasEnvironment(args); + + String outputPathStr = configure.getOutputPath(); + if (outputPathStr == null) { + outputPathStr = ArthasConstants.ARTHAS_OUTPUT; + } + outputPath = new File(outputPathStr); + outputPath.mkdirs(); + // 3. init logger loggerContext = LogUtil.initLooger(arthasEnvironment); - // 4. init beans + // 4. 增强ClassLoader + enhanceClassLoader(); + // 5. init beans initBeans(); - // 5. start agent server + // 6. start agent server bind(configure); executorService = Executors.newScheduledThreadPool(1, new ThreadFactory() { @@ -146,13 +175,21 @@ public class ArthasBootstrap { Runtime.getRuntime().addShutdownHook(shutdown); } + private void initFastjson() { + // disable fastjson circular reference feature + JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.DisableCircularReferenceDetect.getMask(); + // add date format option for fastjson + JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteDateUseDateFormat.getMask(); + // ignore getter error #1661 + JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.IgnoreErrorGetter.getMask(); + } + private void initBeans() { this.resultViewResolver = new ResultViewResolver(); - this.historyManager = new HistoryManagerImpl(); } - private static void initSpy(Instrumentation instrumentation) throws Throwable { + private void initSpy() throws Throwable { // TODO init SpyImpl ? // 将Spy添加到BootstrapClassLoader @@ -177,6 +214,36 @@ public class ArthasBootstrap { } } + void enhanceClassLoader() throws IOException, UnmodifiableClassException { + if (configure.getEnhanceLoaders() == null) { + return; + } + Set loaders = new HashSet(); + for (String s : configure.getEnhanceLoaders().split(",")) { + loaders.add(s.trim()); + } + + // 增强 ClassLoader#loadClsss ,解决一些ClassLoader加载不到 SpyAPI的问题 + // https://github.com/alibaba/arthas/issues/1596 + byte[] classBytes = IOUtils.getBytes(ArthasBootstrap.class.getClassLoader() + .getResourceAsStream(ClassLoader_Instrument.class.getName().replace('.', '/') + ".class")); + + SimpleClassMatcher matcher = new SimpleClassMatcher(loaders); + InstrumentConfig instrumentConfig = new InstrumentConfig(AsmUtils.toClassNode(classBytes), matcher); + + InstrumentParseResult instrumentParseResult = new InstrumentParseResult(); + instrumentParseResult.addInstrumentConfig(instrumentConfig); + classLoaderInstrumentTransformer = new InstrumentTransformer(instrumentParseResult); + instrumentation.addTransformer(classLoaderInstrumentTransformer, true); + + if (loaders.size() == 1 && loaders.contains(ClassLoader.class.getName())) { + // 如果只增强 java.lang.ClassLoader,可以减少查找过程 + instrumentation.retransformClasses(ClassLoader.class); + } else { + InstrumentationUtils.trigerRetransformClasses(instrumentation, loaders); + } + } + private void initArthasEnvironment(Map argsMap) throws IOException { if (arthasEnvironment == null) { arthasEnvironment = new ArthasEnvironment(); @@ -189,7 +256,10 @@ public class ArthasBootstrap { * https://github.com/alibaba/arthas/issues/986 *

*/ - Map copyMap = new HashMap(argsMap); + Map copyMap = new HashMap(); + if (argsMap != null) { + copyMap.putAll(argsMap); + } // 添加 arthas.home if (!copyMap.containsKey(ARTHAS_HOME_PROPERTY)) { copyMap.put(ARTHAS_HOME_PROPERTY, arthasHome()); @@ -222,24 +292,25 @@ public class ArthasBootstrap { return ARTHAS_HOME; } + static String reslove(ArthasEnvironment arthasEnvironment, String key, String defaultValue) { + String value = arthasEnvironment.getProperty(key); + if (value == null) { + return defaultValue; + } + return arthasEnvironment.resolvePlaceholders(value); + } + // try to load arthas.properties private void tryToLoadArthasProperties() throws IOException { this.arthasEnvironment.resolvePlaceholders(CONFIG_LOCATION_PROPERTY); - String location = null; - - if (arthasEnvironment.containsProperty(CONFIG_LOCATION_PROPERTY)) { - location = arthasEnvironment.resolvePlaceholders(CONFIG_LOCATION_PROPERTY); - } + String location = reslove(arthasEnvironment, CONFIG_LOCATION_PROPERTY, null); if (location == null) { location = arthasHome(); } - String configName = "arthas"; - if (arthasEnvironment.containsProperty(CONFIG_NAME_PROPERTY)) { - configName = arthasEnvironment.resolvePlaceholders(CONFIG_NAME_PROPERTY); - } + String configName = reslove(arthasEnvironment, CONFIG_NAME_PROPERTY, "arthas"); if (location != null) { if (!location.endsWith(".properties")) { @@ -257,7 +328,7 @@ public class ArthasBootstrap { overrideAll = Boolean.parseBoolean(properties.getProperty(CONFIG_OVERRIDE_ALL, "false")); } - PropertySource propertySource = new PropertiesPropertySource(location, properties); + PropertySource propertySource = new PropertiesPropertySource(location, properties); if (overrideAll) { arthasEnvironment.addFirst(propertySource); } else { @@ -281,28 +352,31 @@ public class ArthasBootstrap { } // init random port - if (configure.getTelnetPort() == 0) { + if (configure.getTelnetPort() != null && configure.getTelnetPort() == 0) { int newTelnetPort = SocketUtils.findAvailableTcpPort(); configure.setTelnetPort(newTelnetPort); logger().info("generate random telnet port: " + newTelnetPort); } - if (configure.getHttpPort() == 0) { + if (configure.getHttpPort() != null && configure.getHttpPort() == 0) { int newHttpPort = SocketUtils.findAvailableTcpPort(); configure.setHttpPort(newHttpPort); logger().info("generate random http port: " + newHttpPort); } + // try to find appName + if (configure.getAppName() == null) { + configure.setAppName(System.getProperty(ArthasConstants.PROJECT_NAME, + System.getProperty(ArthasConstants.SPRING_APPLICATION_NAME, null))); + } - String agentId = null; try { if (configure.getTunnelServer() != null) { tunnelClient = new TunnelClient(); + tunnelClient.setAppName(configure.getAppName()); tunnelClient.setId(configure.getAgentId()); tunnelClient.setTunnelServerUrl(configure.getTunnelServer()); + tunnelClient.setVersion(ArthasBanner.version()); ChannelFuture channelFuture = tunnelClient.start(); channelFuture.await(10, TimeUnit.SECONDS); - if(channelFuture.isSuccess()) { - agentId = tunnelClient.getId(); - } } } catch (Throwable t) { logger().error("start tunnel client error", t); @@ -312,16 +386,26 @@ public class ArthasBootstrap { ShellServerOptions options = new ShellServerOptions() .setInstrumentation(instrumentation) .setPid(PidUtils.currentLongPid()) - .setSessionTimeout(configure.getSessionTimeout() * 1000); - - if (agentId != null) { - Map welcomeInfos = new HashMap(); - welcomeInfos.put("id", agentId); - options.setWelcomeMessage(ArthasBanner.welcome(welcomeInfos)); + .setWelcomeMessage(ArthasBanner.welcome()); + if (configure.getSessionTimeout() != null) { + options.setSessionTimeout(configure.getSessionTimeout() * 1000); } + this.httpSessionManager = new HttpSessionManager(); + this.securityAuthenticator = new SecurityAuthenticatorImpl(configure.getUsername(), configure.getPassword()); + shellServer = new ShellServerImpl(options); - BuiltinCommandPack builtinCommands = new BuiltinCommandPack(); + + List disabledCommands = new ArrayList(); + if (configure.getDisabledCommands() != null) { + String[] strings = StringUtils.tokenizeToStringArray(configure.getDisabledCommands(), ","); + if (strings != null) { + for (String s : strings) { + disabledCommands.add(s); + } + } + } + BuiltinCommandPack builtinCommands = new BuiltinCommandPack(disabledCommands); List resolvers = new ArrayList(); resolvers.add(builtinCommands); @@ -329,20 +413,22 @@ public class ArthasBootstrap { workerGroup = new NioEventLoopGroup(new DefaultThreadFactory("arthas-TermServer", true)); // TODO: discover user provided command resolver - if (configure.getTelnetPort() > 0) { + if (configure.getTelnetPort() != null && configure.getTelnetPort() > 0) { + logger().info("try to bind telnet server, host: {}, port: {}.", configure.getIp(), configure.getTelnetPort()); shellServer.registerTermServer(new HttpTelnetTermServer(configure.getIp(), configure.getTelnetPort(), - options.getConnectionTimeout(), workerGroup)); + options.getConnectionTimeout(), workerGroup, httpSessionManager)); } else { logger().info("telnet port is {}, skip bind telnet server.", configure.getTelnetPort()); } - if (configure.getHttpPort() > 0) { + if (configure.getHttpPort() != null && configure.getHttpPort() > 0) { + logger().info("try to bind http server, host: {}, port: {}.", configure.getIp(), configure.getHttpPort()); shellServer.registerTermServer(new HttpTermServer(configure.getIp(), configure.getHttpPort(), - options.getConnectionTimeout(), workerGroup)); + options.getConnectionTimeout(), workerGroup, httpSessionManager)); } else { // listen local address in VM communication if (configure.getTunnelServer() != null) { shellServer.registerTermServer(new HttpTermServer(configure.getIp(), configure.getHttpPort(), - options.getConnectionTimeout(), workerGroup)); + options.getConnectionTimeout(), workerGroup, httpSessionManager)); } logger().info("http port is {}, skip bind http server.", configure.getHttpPort()); } @@ -353,7 +439,9 @@ public class ArthasBootstrap { shellServer.listen(new BindHandler(isBindRef)); if (!isBind()) { - throw new IllegalStateException("Arthas failed to bind telnet or http port."); + throw new IllegalStateException("Arthas failed to bind telnet or http port! Telnet port: " + + String.valueOf(configure.getTelnetPort()) + ", http port: " + + String.valueOf(configure.getHttpPort())); } //http api session manager @@ -417,6 +505,9 @@ public class ArthasBootstrap { sessionManager.close(); sessionManager = null; } + if (this.httpSessionManager != null) { + httpSessionManager.stop(); + } if (timer != null) { timer.cancel(); } @@ -433,6 +524,9 @@ public class ArthasBootstrap { if (transformerManager != null) { transformerManager.destroy(); } + if (classLoaderInstrumentTransformer != null) { + instrumentation.removeTransformer(classLoaderInstrumentTransformer); + } // clear the reference in Spy class. cleanUpSpyReference(); shutdownWorkGroup(); @@ -562,4 +656,13 @@ public class ArthasBootstrap { public HttpApiHandler getHttpApiHandler() { return httpApiHandler; } + + public File getOutputPath() { + return outputPath; + } + + public SecurityAuthenticator getSecurityAuthenticator() { + return securityAuthenticator; + } + } diff --git a/core/src/main/java/com/taobao/arthas/core/server/instrument/ClassLoader_Instrument.java b/core/src/main/java/com/taobao/arthas/core/server/instrument/ClassLoader_Instrument.java new file mode 100644 index 000000000..117ad4891 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/server/instrument/ClassLoader_Instrument.java @@ -0,0 +1,24 @@ +package com.taobao.arthas.core.server.instrument; + +import com.alibaba.bytekit.agent.inst.Instrument; +import com.alibaba.bytekit.agent.inst.InstrumentApi; + +/** + * @see java.lang.ClassLoader#loadClass(String) + * @author hengyunabc 2020-11-30 + * + */ +@Instrument(Class = "java.lang.ClassLoader") +public abstract class ClassLoader_Instrument { + public Class loadClass(String name) throws ClassNotFoundException { + if (name.startsWith("java.arthas.")) { + ClassLoader extClassLoader = ClassLoader.getSystemClassLoader().getParent(); + if (extClassLoader != null) { + return extClassLoader.loadClass(name); + } + } + + Class clazz = InstrumentApi.invokeOrigin(); + return clazz; + } +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/cli/CompletionUtils.java b/core/src/main/java/com/taobao/arthas/core/shell/cli/CompletionUtils.java index d3e7c666d..c49e5d125 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/cli/CompletionUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/cli/CompletionUtils.java @@ -320,4 +320,82 @@ public class CompletionUtils { } } } + + /** + *
+     * 检查是否应该补全某个 option。
+     * 比如 option是: --classPattern , tokens可能是:
+     *  2个: '--classPattern' ' '
+     *  3个: '--classPattern' ' ' 'demo.'
+     * 
+ * + * @param option + * @return + */ + public static boolean shouldCompleteOption(Completion completion, String option) { + List tokens = completion.lineTokens(); + // 有两个 tocken, 然后 倒数第一个不是 - 开头的 + if (tokens.size() >= 2) { + CliToken cliToken_1 = tokens.get(tokens.size() - 1); + CliToken cliToken_2 = tokens.get(tokens.size() - 2); + String token_2 = cliToken_2.value(); + if (!cliToken_1.value().startsWith("-") && token_2.equals(option)) { + return CompletionUtils.completeClassName(completion); + } + } + // 有三个 token,然后 倒数第一个不是 - 开头的,倒数第2是空的,倒数第3是 --classPattern + if (tokens.size() >= 3) { + CliToken cliToken_1 = tokens.get(tokens.size() - 1); + CliToken cliToken_2 = tokens.get(tokens.size() - 2); + CliToken cliToken_3 = tokens.get(tokens.size() - 3); + if (!cliToken_1.value().startsWith("-") && cliToken_2.isBlank() + && cliToken_3.value().equals(option)) { + return CompletionUtils.completeClassName(completion); + } + } + return false; + } + + public static boolean completeOptions(Completion completion, List handlers) { + List tokens = completion.lineTokens(); + /** + *
+         * 比如 ` --name a`,这样子的tokens
+         * 
+ */ + if (tokens.size() >= 3) { + CliToken cliToken_2 = tokens.get(tokens.size() - 2); + CliToken cliToken_3 = tokens.get(tokens.size() - 3); + + if (cliToken_2.isBlank()) { + String token_3 = cliToken_3.value(); + + for (OptionCompleteHandler handler : handlers) { + if (handler.matchName(token_3)) { + return handler.complete(completion); + } + } + } + } + + /** + *
+         * 比如 ` --name `,这样子的tokens
+         * 
+ */ + if (tokens.size() >= 2) { + CliToken cliToken_1 = tokens.get(tokens.size() - 1); + CliToken cliToken_2 = tokens.get(tokens.size() - 2); + if (cliToken_1.isBlank()) { + String token_2 = cliToken_2.value(); + for (OptionCompleteHandler handler : handlers) { + if (handler.matchName(token_2)) { + return handler.complete(completion); + } + } + } + } + + return false; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/cli/OptionCompleteHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/cli/OptionCompleteHandler.java new file mode 100644 index 000000000..48778164f --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/shell/cli/OptionCompleteHandler.java @@ -0,0 +1,12 @@ +package com.taobao.arthas.core.shell.cli; + +/** + * + * @author hengyunabc 2021-04-29 + * + */ +public interface OptionCompleteHandler { + boolean matchName(String token); + + boolean complete(Completion completion); +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/history/impl/HistoryManagerImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/history/impl/HistoryManagerImpl.java index 5b22f79bd..c6853a9b7 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/history/impl/HistoryManagerImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/history/impl/HistoryManagerImpl.java @@ -1,5 +1,7 @@ package com.taobao.arthas.core.shell.history.impl; +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; import com.taobao.arthas.core.shell.history.HistoryManager; import com.taobao.arthas.core.util.Constants; import com.taobao.arthas.core.util.FileUtils; @@ -17,28 +19,38 @@ public class HistoryManagerImpl implements HistoryManager { */ private static final int MAX_HISTORY_SIZE = 500; + private static final Logger logger = LoggerFactory.getLogger(HistoryManagerImpl.class); + private List history = new ArrayList(); public HistoryManagerImpl() { } @Override - public void saveHistory() { - FileUtils.saveCommandHistoryString(history, new File(Constants.CMD_HISTORY_FILE)); + public synchronized void saveHistory() { + try { + FileUtils.saveCommandHistoryString(history, new File(Constants.CMD_HISTORY_FILE)); + } catch (Throwable e) { + logger.error("save command history failed", e); + } } @Override - public void loadHistory() { - history = FileUtils.loadCommandHistoryString(new File(Constants.CMD_HISTORY_FILE)); + public synchronized void loadHistory() { + try { + history = FileUtils.loadCommandHistoryString(new File(Constants.CMD_HISTORY_FILE)); + } catch (Throwable e) { + logger.error("load command history failed", e); + } } @Override - public void clearHistory() { + public synchronized void clearHistory() { this.history.clear(); } @Override - public void addHistory(String commandLine) { + public synchronized void addHistory(String commandLine) { while (history.size() >= MAX_HISTORY_SIZE) { history.remove(0); } @@ -46,14 +58,13 @@ public class HistoryManagerImpl implements HistoryManager { } @Override - public List getHistory() { - return history; + public synchronized List getHistory() { + return new ArrayList(history); } @Override - public void setHistory(List history) { + public synchronized void setHistory(List history) { this.history = history; } - } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellImpl.java index a9e3ac54b..f69002adf 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellImpl.java @@ -18,13 +18,18 @@ import com.taobao.arthas.core.shell.system.impl.InternalCommandManager; import com.taobao.arthas.core.shell.system.impl.JobControllerImpl; import com.taobao.arthas.core.shell.term.Term; import com.taobao.arthas.core.shell.term.impl.TermImpl; +import com.taobao.arthas.core.shell.term.impl.http.ExtHttpTtyConnection; import com.taobao.arthas.core.util.Constants; import com.taobao.arthas.core.util.FileUtils; +import io.termd.core.tty.TtyConnection; + import java.io.File; import java.lang.instrument.Instrumentation; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.UUID; @@ -49,6 +54,18 @@ public class ShellImpl implements Shell { public ShellImpl(ShellServer server, Term term, InternalCommandManager commandManager, Instrumentation instrumentation, long pid, JobControllerImpl jobController) { + if (term instanceof TermImpl) { + TermImpl termImpl = (TermImpl) term; + TtyConnection conn = termImpl.getConn(); + if (conn instanceof ExtHttpTtyConnection) { + // 传递http cookie 里的鉴权信息到新建立的session中 + ExtHttpTtyConnection extConn = (ExtHttpTtyConnection) conn; + Map extSessions = extConn.extSessions(); + for (Entry entry : extSessions.entrySet()) { + session.put(entry.getKey(), entry.getValue()); + } + } + } session.put(Session.COMMAND_MANAGER, commandManager); session.put(Session.INSTRUMENTATION, instrumentation); session.put(Session.PID, pid); diff --git a/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellServerImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellServerImpl.java index 71e68d292..38934d79a 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellServerImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/impl/ShellServerImpl.java @@ -2,6 +2,7 @@ package com.taobao.arthas.core.shell.impl; import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.alibaba.arthas.tunnel.client.TunnelClient; import com.taobao.arthas.core.server.ArthasBootstrap; import com.taobao.arthas.core.shell.Shell; import com.taobao.arthas.core.shell.ShellServer; @@ -19,10 +20,12 @@ import com.taobao.arthas.core.shell.system.impl.InternalCommandManager; import com.taobao.arthas.core.shell.system.impl.JobControllerImpl; import com.taobao.arthas.core.shell.term.Term; import com.taobao.arthas.core.shell.term.TermServer; +import com.taobao.arthas.core.util.ArthasBanner; import java.lang.instrument.Instrumentation; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -93,6 +96,7 @@ public class ShellServerImpl extends ShellServer { } ShellImpl session = createShell(term); + tryUpdateWelcomeMessage(); session.setWelcome(welcomeMessage); session.closedFuture.setHandler(new SessionClosedHandler(this, session)); session.init(); @@ -100,6 +104,18 @@ public class ShellServerImpl extends ShellServer { session.readline(); // Now readline } + private void tryUpdateWelcomeMessage() { + TunnelClient tunnelClient = ArthasBootstrap.getInstance().getTunnelClient(); + if (tunnelClient != null) { + String id = tunnelClient.getId(); + if (id != null) { + Map welcomeInfos = new HashMap(); + welcomeInfos.put("id", id); + this.welcomeMessage = ArthasBanner.welcome(welcomeInfos); + } + } + } + @Override public ShellServer listen(final Handler> listenHandler) { final List toStart; diff --git a/core/src/main/java/com/taobao/arthas/core/shell/session/impl/SessionManagerImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/session/impl/SessionManagerImpl.java index c3800ce5b..e8e4d4cca 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/session/impl/SessionManagerImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/session/impl/SessionManagerImpl.java @@ -71,6 +71,22 @@ public class SessionManagerImpl implements SessionManager { @Override public Session removeSession(String sessionId) { + Session session = sessions.get(sessionId); + if (session == null) { + return null; + } + + //interrupt foreground job + Job job = session.getForegroundJob(); + if (job != null) { + job.interrupt(); + } + + SharingResultDistributor resultDistributor = session.getResultDistributor(); + if (resultDistributor != null) { + resultDistributor.close(); + } + return sessions.remove(sessionId); } @@ -90,8 +106,9 @@ public class SessionManagerImpl implements SessionManager { ArrayList sessions = new ArrayList(this.sessions.values()); for (Session session : sessions) { SharingResultDistributor resultDistributor = session.getResultDistributor(); - resultDistributor.appendResult(new MessageModel("arthas server is going to shutdown.")); - resultDistributor.close(); + if (resultDistributor != null) { + resultDistributor.appendResult(new MessageModel("arthas server is going to shutdown.")); + } logger.info("Removing session before shutdown: {}, last access time: {}", session.getSessionId(), session.getLastAccessTime()); this.removeSession(session.getSessionId()); } @@ -142,7 +159,10 @@ public class SessionManagerImpl implements SessionManager { } long timeOutInMinutes = sessionTimeoutMillis / 1000 / 60; String reason = "session is inactive for " + timeOutInMinutes + " min(s)."; - session.getResultDistributor().appendResult(new MessageModel(reason)); + SharingResultDistributor resultDistributor = session.getResultDistributor(); + if (resultDistributor != null) { + resultDistributor.appendResult(new MessageModel(reason)); + } this.removeSession(session.getSessionId()); logger.info("Removing inactive session: {}, last access time: {}", session.getSessionId(), session.getLastAccessTime()); } @@ -153,7 +173,7 @@ public class SessionManagerImpl implements SessionManager { */ public void evictConsumers(Session session) { SharingResultDistributor distributor = session.getResultDistributor(); - if (distributor instanceof SharingResultDistributor) { + if (distributor != null && distributor instanceof SharingResultDistributor) { SharingResultDistributor sharingResultDistributor = (SharingResultDistributor) distributor; List consumers = sharingResultDistributor.getConsumers(); //remove inactive consumer from session directly diff --git a/core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java index e21b3551d..d8880f8e5 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/system/impl/JobControllerImpl.java @@ -1,7 +1,9 @@ package com.taobao.arthas.core.shell.system.impl; +import com.taobao.arthas.common.ArthasConstants; import com.taobao.arthas.core.GlobalOptions; import com.taobao.arthas.core.distribution.ResultDistributor; +import com.taobao.arthas.core.server.ArthasBootstrap; import com.taobao.arthas.core.shell.cli.CliToken; import com.taobao.arthas.core.shell.command.Command; import com.taobao.arthas.core.shell.command.internal.RedirectHandler; @@ -60,15 +62,30 @@ public class JobControllerImpl implements JobController { return jobs.remove(id) != null; } + private void checkPermission(Session session, CliToken token) { + if (ArthasBootstrap.getInstance().getSecurityAuthenticator().needLogin()) { + // 检查session是否有 Subject + Object subject = session.get(ArthasConstants.SUBJECT_KEY); + if (subject == null) { + if (token != null && token.isText() && token.value().trim().equals(ArthasConstants.AUTH)) { + // 执行的是auth 命令 + return; + } + throw new IllegalArgumentException("Error! command not permitted, try to use 'auth' command to authenticates."); + } + } + } + @Override public Job createJob(InternalCommandManager commandManager, List tokens, Session session, JobListener jobHandler, Term term, ResultDistributor resultDistributor) { + checkPermission(session, tokens.get(0)); int jobId = idGenerator.incrementAndGet(); StringBuilder line = new StringBuilder(); for (CliToken arg : tokens) { line.append(arg.raw()); } boolean runInBackground = runInBackground(tokens); - Process process = createProcess(tokens, commandManager, jobId, term, resultDistributor); + Process process = createProcess(session, tokens, commandManager, jobId, term, resultDistributor); process.setJobId(jobId); JobImpl job = new JobImpl(jobId, this, process, line.toString(), runInBackground, session, jobHandler); jobs.put(jobId, job); @@ -126,12 +143,14 @@ public class JobControllerImpl implements JobController { * @param resultDistributor * @return the created process */ - private Process createProcess(List line, InternalCommandManager commandManager, int jobId, Term term, ResultDistributor resultDistributor) { + private Process createProcess(Session session, List line, InternalCommandManager commandManager, int jobId, Term term, ResultDistributor resultDistributor) { try { ListIterator tokens = line.listIterator(); while (tokens.hasNext()) { CliToken token = tokens.next(); if (token.isText()) { + // check before create process + checkPermission(session, token); Command command = commandManager.getCommand(token.value()); if (command != null) { return createCommandProcess(command, tokens, jobId, term, resultDistributor); diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/TermServer.java b/core/src/main/java/com/taobao/arthas/core/shell/term/TermServer.java index af5ab912b..dde1f3633 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/TermServer.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/TermServer.java @@ -1,5 +1,6 @@ package com.taobao.arthas.core.shell.term; +import com.taobao.arthas.common.ArthasConstants; import com.taobao.arthas.core.config.Configure; import com.taobao.arthas.core.shell.ShellServerOptions; import com.taobao.arthas.core.shell.future.Future; @@ -20,7 +21,8 @@ public abstract class TermServer { * @return the term server */ public static TermServer createTelnetTermServer(Configure configure, ShellServerOptions options) { - return new TelnetTermServer(configure.getIp(), configure.getTelnetPort(), options.getConnectionTimeout()); + int port = configure.getTelnetPort() != null ? configure.getTelnetPort() : ArthasConstants.TELNET_PORT; + return new TelnetTermServer(configure.getIp(), port, options.getConnectionTimeout()); } /** diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/HttpTermServer.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/HttpTermServer.java index c8dafe942..73ee3cc89 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/HttpTermServer.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/HttpTermServer.java @@ -7,6 +7,8 @@ import com.taobao.arthas.core.shell.handlers.Handler; import com.taobao.arthas.core.shell.term.Term; import com.taobao.arthas.core.shell.term.TermServer; import com.taobao.arthas.core.shell.term.impl.http.NettyWebsocketTtyBootstrap; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; + import io.netty.util.concurrent.EventExecutorGroup; import io.termd.core.function.Consumer; import io.termd.core.tty.TtyConnection; @@ -26,12 +28,14 @@ public class HttpTermServer extends TermServer { private int port; private long connectionTimeout; private EventExecutorGroup workerGroup; + private HttpSessionManager httpSessionManager; - public HttpTermServer(String hostIp, int port, long connectionTimeout, EventExecutorGroup workerGroup) { + public HttpTermServer(String hostIp, int port, long connectionTimeout, EventExecutorGroup workerGroup, HttpSessionManager httpSessionManager) { this.hostIp = hostIp; this.port = port; this.connectionTimeout = connectionTimeout; this.workerGroup = workerGroup; + this.httpSessionManager = httpSessionManager; } @Override @@ -43,7 +47,7 @@ public class HttpTermServer extends TermServer { @Override public TermServer listen(Handler> listenHandler) { // TODO: charset and inputrc from options - bootstrap = new NettyWebsocketTtyBootstrap(workerGroup).setHost(hostIp).setPort(port); + bootstrap = new NettyWebsocketTtyBootstrap(workerGroup, httpSessionManager).setHost(hostIp).setPort(port); try { bootstrap.start(new Consumer() { @Override diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/TermImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/TermImpl.java index 34731be58..1a47e8c6f 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/TermImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/TermImpl.java @@ -221,6 +221,10 @@ public class TermImpl implements Term { } } + public TtyConnection getConn() { + return conn; + } + public void echo(int... codePoints) { Consumer out = conn.stdoutHandler(); for (int codePoint : codePoints) { diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/BasicHttpAuthenticatorHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/BasicHttpAuthenticatorHandler.java new file mode 100644 index 000000000..b14975cd1 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/BasicHttpAuthenticatorHandler.java @@ -0,0 +1,171 @@ +package com.taobao.arthas.core.shell.term.impl.http; + +import java.nio.charset.Charset; +import java.util.List; +import java.util.Map; + +import javax.security.auth.Subject; + +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.security.BasicPrincipal; +import com.taobao.arthas.core.security.SecurityAuthenticator; +import com.taobao.arthas.core.server.ArthasBootstrap; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSession; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; +import com.taobao.arthas.core.util.StringUtils; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelDuplexHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; +import io.netty.handler.codec.base64.Base64; +import io.netty.handler.codec.http.DefaultHttpResponse; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpResponse; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.util.Attribute; + +/** + * + * @author hengyunabc 2021-03-03 + * + */ +public final class BasicHttpAuthenticatorHandler extends ChannelDuplexHandler { + private static final Logger logger = LoggerFactory.getLogger(BasicHttpAuthenticatorHandler.class); + + private HttpSessionManager httpSessionManager; + + private SecurityAuthenticator securityAuthenticator = ArthasBootstrap.getInstance().getSecurityAuthenticator(); + + public BasicHttpAuthenticatorHandler(HttpSessionManager httpSessionManager) { + this.httpSessionManager = httpSessionManager; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + if (!securityAuthenticator.needLogin()) { + ctx.fireChannelRead(msg); + return; + } + + boolean authed = false; + if (msg instanceof HttpRequest) { + HttpRequest httpRequest = (HttpRequest) msg; + + // 判断session里是否有已登陆信息 + HttpSession session = httpSessionManager.getOrCreateHttpSession(ctx, httpRequest); + if (session != null && session.getAttribute(ArthasConstants.SUBJECT_KEY) != null) { + authed = true; + } + + if (!authed) { + // 判断请求header里是否带有 username/password + BasicPrincipal principal = extractBasicAuthSubject(httpRequest); + if (principal == null) { + // 判断 url里是否有 username/password + principal = extractBasicAuthSubjectFromUrl(httpRequest); + } + Subject subject = securityAuthenticator.login(principal); + if (subject != null) { + authed = true; + session.setAttribute(ArthasConstants.SUBJECT_KEY, subject); + } + } + + if (!authed) { + // restricted resource, so send back 401 to require valid username/password + HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED); + response.headers().set(HttpHeaderNames.WWW_AUTHENTICATE, "Basic realm=\"arthas webconsole\""); + response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain"); + response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0); + + ctx.writeAndFlush(response); + // close the channel + ctx.channel().close(); + return; + } + + } + + ctx.fireChannelRead(msg); + } + + @Override + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + if (msg instanceof HttpResponse) { + // write cookie + HttpResponse response = (HttpResponse) msg; + Attribute attribute = ctx.channel().attr(HttpSessionManager.SESSION_KEY); + HttpSession session = attribute.get(); + if (session != null) { + HttpSessionManager.setSessionCookie(response, session); + } + } + super.write(ctx, msg, promise); + } + + /** + * 从url参数里提取 ?username=hello&password=world + * + * @param request + * @return + */ + protected static BasicPrincipal extractBasicAuthSubjectFromUrl(HttpRequest request) { + QueryStringDecoder queryDecoder = new QueryStringDecoder(request.uri()); + Map> parameters = queryDecoder.parameters(); + + List passwords = parameters.get(ArthasConstants.PASSWORD_KEY); + if (passwords == null || passwords.size() == 0) { + return null; + } + String password = passwords.get(0); + + String username = ArthasConstants.DEFAULT_USERNAME; + List usernames = parameters.get(ArthasConstants.USERNAME_KEY); + if (usernames != null && !usernames.isEmpty()) { + username = usernames.get(0); + } + BasicPrincipal principal = new BasicPrincipal(username, password); + logger.debug("Extracted Basic Auth principal from url: {}", principal); + return principal; + } + + /** + * Extracts the username and password details from the HTTP basic header + * Authorization. + *

+ * This requires that the Authorization HTTP header is provided, and + * its using Basic. Currently Digest is not supported. + * + * @return {@link HttpPrincipal} with username and password details, or + * null if not possible to extract + */ + protected static BasicPrincipal extractBasicAuthSubject(HttpRequest request) { + String auth = request.headers().get(HttpHeaderNames.AUTHORIZATION); + if (auth != null) { + String constraint = StringUtils.before(auth, " "); + if (constraint != null) { + if ("Basic".equalsIgnoreCase(constraint.trim())) { + String decoded = StringUtils.after(auth, " "); + // the decoded part is base64 encoded, so we need to decode that + ByteBuf buf = Unpooled.wrappedBuffer(decoded.getBytes()); + ByteBuf out = Base64.decode(buf); + String userAndPw = out.toString(Charset.defaultCharset()); + String username = StringUtils.before(userAndPw, ":"); + String password = StringUtils.after(userAndPw, ":"); + BasicPrincipal principal = new BasicPrincipal(username, password); + logger.debug("Extracted Basic Auth principal from HTTP header: {}", principal); + return principal; + } + } + } + return null; + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/DirectoryBrowser.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/DirectoryBrowser.java index 5ab46822a..fcb2c578c 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/DirectoryBrowser.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/DirectoryBrowser.java @@ -3,17 +3,41 @@ package com.taobao.arthas.core.shell.term.impl.http; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.RandomAccessFile; import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; +import com.taobao.arthas.common.ArthasConstants; import com.taobao.arthas.common.IOUtils; - +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelProgressiveFuture; +import io.netty.channel.ChannelProgressiveFutureListener; +import io.netty.channel.DefaultFileRegion; import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.DefaultHttpResponse; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpChunkedInput; import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.ssl.SslHandler; +import io.netty.handler.stream.ChunkedFile; + +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; /** * @@ -22,6 +46,10 @@ import io.netty.handler.codec.http.HttpVersion; */ public class DirectoryBrowser { + public static final String HTTP_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz"; + public static final String HTTP_DATE_GMT_TIMEZONE = "GMT"; + public static final long MIN_NETTY_DIRECT_SEND_SIZE = ArthasConstants.MAX_HTTP_CONTENT_LENGTH; + private static final Logger logger = LoggerFactory.getLogger(DirectoryBrowser.class); //@formatter:off private static String pageHeader = "\n" + "\n" + @@ -55,7 +83,7 @@ public class DirectoryBrowser { private static String linePart1Str = ""; private static String linePart2Str = "%-60s"; - private static String renderDir(File dir) { + static String renderDir(File dir) { File[] listFiles = dir.listFiles(); StringBuilder sb = new StringBuilder(8192); @@ -108,12 +136,24 @@ public class DirectoryBrowser { return sb.toString(); } - public static DefaultFullHttpResponse view(File dir, String path, HttpVersion version) throws IOException { + /** + * write data here,still return not null just to know succeeded. + * @param dir + * @param path + * @param request + * @param ctx + * @return + * @throws IOException + */ + public static DefaultFullHttpResponse directView(File dir, String path, FullHttpRequest request, ChannelHandlerContext ctx) throws IOException { if (path.startsWith("/")) { path = path.substring(1, path.length()); } - File file = new File(path); + // path maybe: arthas-output/20201225-203454.svg + // 需要取 dir的parent来去掉前缀 + File file = new File(dir.getParent(), path); + HttpVersion version = request.protocolVersion(); if (isSubFile(dir, file)) { DefaultFullHttpResponse fullResp = new DefaultFullHttpResponse(version, HttpResponseStatus.OK); @@ -125,22 +165,112 @@ public class DirectoryBrowser { String renderResult = renderDir(file); fullResp.content().writeBytes(renderResult.getBytes("utf-8")); fullResp.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=utf-8"); + ctx.write(fullResp); + ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + future.addListener(ChannelFutureListener.CLOSE); + return fullResp; } else { - FileInputStream fileInputStream = new FileInputStream(file); + logger.info("get file now. file:" + file.getPath()); + if (file.isHidden() || !file.exists() || file.isDirectory() || !file.isFile()) { + return null; + } + + RandomAccessFile raf; try { - byte[] content = IOUtils.getBytes(fileInputStream); - fullResp.content().writeBytes(content); - HttpUtil.setContentLength(fullResp, fullResp.content().readableBytes()); - } finally { - IOUtils.close(fileInputStream); + raf = new RandomAccessFile(file, "r"); + } catch (Exception ignore) { + return null; + } + long fileLength = raf.length(); + if (fileLength < MIN_NETTY_DIRECT_SEND_SIZE){ + FileInputStream fileInputStream = new FileInputStream(file); + try { + byte[] content = IOUtils.getBytes(fileInputStream); + fullResp.content().writeBytes(content); + HttpUtil.setContentLength(fullResp, fullResp.content().readableBytes()); + } finally { + IOUtils.close(fileInputStream); + } + ctx.write(fullResp); + ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + future.addListener(ChannelFutureListener.CLOSE); + return fullResp; + } + logger.info("file {} size bigger than {}, send by future.",file.getName(), MIN_NETTY_DIRECT_SEND_SIZE); + HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); + HttpUtil.setContentLength(response, fileLength); + setContentTypeHeader(response, file); + setDateAndCacheHeaders(response, file); + if (HttpUtil.isKeepAlive(request)) { + response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); + } + + // Write the initial line and the header. + ctx.write(response); + // Write the content. + ChannelFuture sendFileFuture; + ChannelFuture lastContentFuture; + if (ctx.pipeline().get(SslHandler.class) == null) { + sendFileFuture = + ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise()); + // Write the end marker. + lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + } else { + sendFileFuture = + ctx.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, fileLength, 8192)), + ctx.newProgressivePromise()); + // HttpChunkedInput will write the end marker (LastHttpContent) for us. + lastContentFuture = sendFileFuture; } + + sendFileFuture.addListener(new ChannelProgressiveFutureListener() { + @Override + public void operationProgressed(ChannelProgressiveFuture future, long progress, long total) { + if (total < 0) { // total unknown + logger.info(future.channel() + " Transfer progress: " + progress); + } else { + logger.info(future.channel() + " Transfer progress: " + progress + " / " + total); + } + } + + @Override + public void operationComplete(ChannelProgressiveFuture future) { + logger.info(future.channel() + " Transfer complete."); + } + }); + + // Decide whether to close the connection or not. + if (!HttpUtil.isKeepAlive(request)) { + // Close the connection when the whole content is written out. + lastContentFuture.addListener(ChannelFutureListener.CLOSE); + } + return fullResp; } - return fullResp; } return null; } + private static void setDateAndCacheHeaders(HttpResponse response, File fileToCache) { + SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); + dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); + // Date header + Calendar time = new GregorianCalendar(); + response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time.getTime())); + + // Add cache headers + time.add(Calendar.SECOND, 3600); + response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.getTime())); + response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + 3600); + response.headers().set( + HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified()))); + } + + private static void setContentTypeHeader(HttpResponse response, File file) { + String contentType = "application/octet-stream"; + // 暂时hardcode 大文件的content-type + response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType); + } public static boolean isSubFile(File parent, File child) throws IOException { String parentPath = parent.getCanonicalPath(); String childPath = child.getCanonicalPath(); diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/ExtHttpTtyConnection.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/ExtHttpTtyConnection.java new file mode 100644 index 000000000..06f957fa3 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/ExtHttpTtyConnection.java @@ -0,0 +1,76 @@ +package com.taobao.arthas.core.shell.term.impl.http; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSession; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.termd.core.http.HttpTtyConnection; + +/** + * 从http请求传递过来的 session 信息。解析websocket创建的 term 还需要登陆验证问题 + * + * @author hengyunabc 2021-03-04 + * + */ +public class ExtHttpTtyConnection extends HttpTtyConnection { + private ChannelHandlerContext context; + + public ExtHttpTtyConnection(ChannelHandlerContext context) { + this.context = context; + } + + @Override + protected void write(byte[] buffer) { + ByteBuf byteBuf = Unpooled.buffer(); + byteBuf.writeBytes(buffer); + if (context != null) { + context.writeAndFlush(new TextWebSocketFrame(byteBuf)); + } + } + + @Override + public void schedule(Runnable task, long delay, TimeUnit unit) { + if (context != null) { + context.executor().schedule(task, delay, unit); + } + } + + @Override + public void execute(Runnable task) { + if (context != null) { + context.executor().execute(task); + } + } + + @Override + public void close() { + if (context != null) { + context.close(); + } + } + + public Map extSessions() { + if (context != null) { + HttpSession httpSession = HttpSessionManager.getHttpSessionFromContext(context); + if (httpSession != null) { + Object subject = httpSession.getAttribute(ArthasConstants.SUBJECT_KEY); + if (subject != null) { + Map result = new HashMap(); + result.put(ArthasConstants.SUBJECT_KEY, subject); + return result; + } + } + } + return Collections.emptyMap(); + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/HttpRequestHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/HttpRequestHandler.java index b38cba88b..9978a140b 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/HttpRequestHandler.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/HttpRequestHandler.java @@ -1,18 +1,11 @@ package com.taobao.arthas.core.shell.term.impl.http; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URL; - import com.alibaba.arthas.deps.org.slf4j.Logger; import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; import com.taobao.arthas.common.IOUtils; import com.taobao.arthas.core.server.ArthasBootstrap; import com.taobao.arthas.core.shell.term.impl.http.api.HttpApiHandler; import com.taobao.arthas.core.shell.term.impl.httptelnet.HttpTelnetTermServer; - import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -24,13 +17,19 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpUtil; -import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.LastHttpContent; import io.termd.core.http.HttpTtyConnection; import io.termd.core.util.Logging; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + import static com.taobao.arthas.core.util.HttpUtils.createRedirectResponse; import static com.taobao.arthas.core.util.HttpUtils.createResponse; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; /** * @author Julien Viet @@ -46,6 +45,11 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new ChunkedWriteHandler()); - pipeline.addLast(new HttpObjectAggregator(64 * 1024)); - pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File("arthas-output"))); - pipeline.addLast(new WebSocketServerProtocolHandler("/ws")); + pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH)); + pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH)); + pipeline.addLast(new WebSocketServerProtocolHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH, true)); + pipeline.addLast(new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS)); pipeline.addLast(new TtyWebSocketFrameHandler(group, handler)); } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/NettyWebsocketTtyBootstrap.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/NettyWebsocketTtyBootstrap.java index 15503b979..81421328a 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/NettyWebsocketTtyBootstrap.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/NettyWebsocketTtyBootstrap.java @@ -1,6 +1,7 @@ package com.taobao.arthas.core.shell.term.impl.http; import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -37,11 +38,13 @@ public class NettyWebsocketTtyBootstrap { private EventLoopGroup group; private Channel channel; private EventExecutorGroup workerGroup; + private HttpSessionManager httpSessionManager; - public NettyWebsocketTtyBootstrap(EventExecutorGroup workerGroup) { + public NettyWebsocketTtyBootstrap(EventExecutorGroup workerGroup, HttpSessionManager httpSessionManager) { this.workerGroup = workerGroup; this.host = "localhost"; this.port = 8080; + this.httpSessionManager = httpSessionManager; } public String getHost() { @@ -68,7 +71,7 @@ public class NettyWebsocketTtyBootstrap { if (this.port > 0) { ServerBootstrap b = new ServerBootstrap(); b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new TtyServerInitializer(channelGroup, handler, workerGroup)); + .childHandler(new TtyServerInitializer(channelGroup, handler, workerGroup, httpSessionManager)); final ChannelFuture f = b.bind(host, port); f.addListener(new GenericFutureListener>() { diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java index 57ba3c9a6..b130cb8ca 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java @@ -1,5 +1,8 @@ package com.taobao.arthas.core.shell.term.impl.http; +import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; + import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.group.ChannelGroup; @@ -8,12 +11,11 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; import io.netty.handler.stream.ChunkedWriteHandler; +import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.concurrent.EventExecutorGroup; import io.termd.core.function.Consumer; import io.termd.core.tty.TtyConnection; -import java.io.File; - /** * @author Julien Viet @@ -23,11 +25,13 @@ public class TtyServerInitializer extends ChannelInitializer { private final ChannelGroup group; private final Consumer handler; private EventExecutorGroup workerGroup; + private HttpSessionManager httpSessionManager; - public TtyServerInitializer(ChannelGroup group, Consumer handler, EventExecutorGroup workerGroup) { + public TtyServerInitializer(ChannelGroup group, Consumer handler, EventExecutorGroup workerGroup, HttpSessionManager httpSessionManager) { this.group = group; this.handler = handler; - this.workerGroup = workerGroup; + this.workerGroup = workerGroup; + this.httpSessionManager = httpSessionManager; } @Override @@ -36,9 +40,11 @@ public class TtyServerInitializer extends ChannelInitializer { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new ChunkedWriteHandler()); - pipeline.addLast(new HttpObjectAggregator(64 * 1024)); - pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File("arthas-output"))); - pipeline.addLast(new WebSocketServerProtocolHandler("/ws")); + pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH)); + pipeline.addLast(new BasicHttpAuthenticatorHandler(httpSessionManager)); + pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH)); + pipeline.addLast(new WebSocketServerProtocolHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH, true)); + pipeline.addLast(new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS)); pipeline.addLast(new TtyWebSocketFrameHandler(group, handler)); } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandler.java index cf7c6a32c..527166592 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandler.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandler.java @@ -16,18 +16,17 @@ package com.taobao.arthas.core.shell.term.impl.http; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.group.ChannelGroup; +import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; +import io.netty.handler.timeout.IdleStateEvent; import io.termd.core.function.Consumer; import io.termd.core.http.HttpTtyConnection; import io.termd.core.tty.TtyConnection; -import java.util.concurrent.TimeUnit; /** * @author Julien Viet @@ -55,38 +54,10 @@ public class TtyWebSocketFrameHandler extends SimpleChannelInboundHandlerlong specifying when this session was created, + * expressed in milliseconds since 1/1/1970 GMT + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public long getCreationTime(); + + /** + * Returns a string containing the unique identifier assigned to this session. + * The identifier is assigned by the servlet container and is implementation + * dependent. + * + * @return a string specifying the identifier assigned to this session + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public String getId(); + + /** + * Returns the last time the client sent a request associated with this session, + * as the number of milliseconds since midnight January 1, 1970 GMT, and marked + * by the time the container received the request. + *

+ * Actions that your application takes, such as getting or setting a value + * associated with the session, do not affect the access time. + * + * @return a long representing the last time the client sent a + * request associated with this session, expressed in milliseconds since + * 1/1/1970 GMT + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public long getLastAccessedTime(); + + /** + * Specifies the time, in seconds, between client requests before the servlet + * container will invalidate this session. A zero or negative time indicates + * that the session should never timeout. + * + * @param interval An integer specifying the number of seconds + */ + public void setMaxInactiveInterval(int interval); + + /** + * Returns the maximum time interval, in seconds, that the servlet container + * will keep this session open between client accesses. After this interval, the + * servlet container will invalidate the session. The maximum time interval can + * be set with the setMaxInactiveInterval method. A zero or + * negative time indicates that the session should never timeout. + * + * @return an integer specifying the number of seconds this session remains open + * between client requests + * @see #setMaxInactiveInterval + */ + public int getMaxInactiveInterval(); + + /** + * Returns the object bound with the specified name in this session, or + * null if no object is bound under the name. + * + * @param name a string specifying the name of the object + * @return the object with the specified name + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public Object getAttribute(String name); + + /** + * Returns an Enumeration of String objects containing + * the names of all the objects bound to this session. + * + * @return an Enumeration of String objects specifying + * the names of all the objects bound to this session + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public Enumeration getAttributeNames(); + + /** + * Binds an object to this session, using the name specified. If an object of + * the same name is already bound to the session, the object is replaced. + *

+ * After this method executes, and if the new object implements + * HttpSessionBindingListener, the container calls + * HttpSessionBindingListener.valueBound. The container then + * notifies any HttpSessionAttributeListeners in the web + * application. + *

+ * If an object was already bound to this session of this name that implements + * HttpSessionBindingListener, its + * HttpSessionBindingListener.valueUnbound method is called. + *

+ * If the value passed in is null, this has the same effect as calling + * removeAttribute(). + * + * @param name the name to which the object is bound; cannot be null + * @param value the object to be bound + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public void setAttribute(String name, Object value); + + /** + * Removes the object bound with the specified name from this session. If the + * session does not have an object bound with the specified name, this method + * does nothing. + *

+ * After this method executes, and if the object implements + * HttpSessionBindingListener, the container calls + * HttpSessionBindingListener.valueUnbound. The container then + * notifies any HttpSessionAttributeListeners in the web + * application. + * + * @param name the name of the object to remove from this session + * @exception IllegalStateException if this method is called on an invalidated + * session + */ + public void removeAttribute(String name); + + /** + * Invalidates this session then unbinds any objects bound to it. + * + * @exception IllegalStateException if this method is called on an already + * invalidated session + */ + public void invalidate(); + + /** + * Returns true if the client does not yet know about the session + * or if the client chooses not to join the session. For example, if the server + * used only cookie-based sessions, and the client had disabled the use of + * cookies, then a session would be new on each request. + * + * @return true if the server has created a session, but the client + * has not yet joined + * @exception IllegalStateException if this method is called on an already + * invalidated session + */ + public boolean isNew(); +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/HttpSessionManager.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/HttpSessionManager.java new file mode 100644 index 000000000..607fbfb05 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/HttpSessionManager.java @@ -0,0 +1,95 @@ +package com.taobao.arthas.core.shell.term.impl.http.session; + +import java.util.Collections; +import java.util.Set; + +import com.taobao.arthas.common.ArthasConstants; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpResponse; +import io.netty.handler.codec.http.cookie.Cookie; +import io.netty.handler.codec.http.cookie.ServerCookieDecoder; +import io.netty.handler.codec.http.cookie.ServerCookieEncoder; +import io.netty.util.Attribute; +import io.netty.util.AttributeKey; + +/** + *

+ * netty里的http session管理。因为同一域名的不同端口共享cookie,所以需要共用。
+ * 
+ * + * @author hengyunabc 2021-03-03 + * + */ +public class HttpSessionManager { + public static AttributeKey SESSION_KEY = AttributeKey.valueOf("session"); + + private LRUCache sessions = new LRUCache(1024); + + public HttpSessionManager() { + + } + + private HttpSession getSession(HttpRequest httpRequest) { + // TODO 增加从 url中获取 session id 功能? + + Set cookies; + String value = httpRequest.headers().get(HttpHeaderNames.COOKIE); + if (value == null) { + cookies = Collections.emptySet(); + } else { + cookies = ServerCookieDecoder.STRICT.decode(value); + } + for (Cookie cookie : cookies) { + if (ArthasConstants.ASESSION_KEY.equals(cookie.name())) { + String sessionId = cookie.value(); + return sessions.get(sessionId); + } + } + return null; + } + + public static HttpSession getHttpSessionFromContext(ChannelHandlerContext ctx) { + return ctx.channel().attr(SESSION_KEY).get(); + } + + public HttpSession getOrCreateHttpSession(ChannelHandlerContext ctx, HttpRequest httpRequest) { + // 尝试用 ctx 和从 cookie里读取出 session + Attribute attribute = ctx.channel().attr(SESSION_KEY); + HttpSession httpSession = attribute.get(); + if (httpSession != null) { + return httpSession; + } + httpSession = getSession(httpRequest); + if (httpSession != null) { + attribute.set(httpSession); + return httpSession; + } + // 创建session,并设置到ctx里 + httpSession = newHttpSession(); + attribute.set(httpSession); + return httpSession; + } + + private HttpSession newHttpSession() { + SimpleHttpSession session = new SimpleHttpSession(); + this.sessions.put(session.getId(), session); + return session; + } + + public static void setSessionCookie(HttpResponse response, HttpSession session) { + response.headers().add(HttpHeaderNames.SET_COOKIE, + ServerCookieEncoder.STRICT.encode(ArthasConstants.ASESSION_KEY, session.getId())); + } + + public void start() { + + } + + public void stop() { + sessions.clear(); + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java new file mode 100644 index 000000000..f5b659925 --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/LRUCache.java @@ -0,0 +1,100 @@ +package com.taobao.arthas.core.shell.term.impl.http.session; + +import java.util.LinkedHashMap; +import java.util.Collection; +import java.util.Map; +import java.util.ArrayList; + +/** + * An LRU cache, based on LinkedHashMap. + * + *

+ * This cache has a fixed maximum number of elements (cacheSize). + * If the cache is full and another entry is added, the LRU (least recently + * used) entry is dropped. + * + *

+ * This class is thread-safe. All methods of this class are synchronized. + * + *

+ * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
+ * Multi-licensed: EPL / LGPL / GPL / AL / BSD. + */ +public class LRUCache { + + private static final float hashTableLoadFactor = 0.75f; + + private LinkedHashMap map; + private int cacheSize; + + /** + * Creates a new LRU cache. + * + * @param cacheSize the maximum number of entries that will be kept in this + * cache. + */ + public LRUCache(int cacheSize) { + this.cacheSize = cacheSize; + int hashTableCapacity = (int) Math.ceil(cacheSize / hashTableLoadFactor) + 1; + map = new LinkedHashMap(hashTableCapacity, hashTableLoadFactor, true) { + // (an anonymous inner class) + private static final long serialVersionUID = 1; + + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > LRUCache.this.cacheSize; + } + }; + } + + /** + * Retrieves an entry from the cache.
+ * The retrieved entry becomes the MRU (most recently used) entry. + * + * @param key the key whose associated value is to be returned. + * @return the value associated to this key, or null if no value with this key + * exists in the cache. + */ + public synchronized V get(K key) { + return map.get(key); + } + + /** + * Adds an entry to this cache. The new entry becomes the MRU (most recently + * used) entry. If an entry with the specified key already exists in the cache, + * it is replaced by the new entry. If the cache is full, the LRU (least + * recently used) entry is removed from the cache. + * + * @param key the key with which the specified value is to be associated. + * @param value a value to be associated with the specified key. + */ + public synchronized void put(K key, V value) { + map.put(key, value); + } + + /** + * Clears the cache. + */ + public synchronized void clear() { + map.clear(); + } + + /** + * Returns the number of used entries in the cache. + * + * @return the number of entries currently in the cache. + */ + public synchronized int usedEntries() { + return map.size(); + } + + /** + * Returns a Collection that contains a copy of all cache entries. + * + * @return a Collection with a copy of the cache content. + */ + public synchronized Collection> getAll() { + return new ArrayList>(map.entrySet()); + } + +} // end class LRUCache diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/SimpleHttpSession.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/SimpleHttpSession.java new file mode 100644 index 000000000..230f82dcc --- /dev/null +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/session/SimpleHttpSession.java @@ -0,0 +1,79 @@ +package com.taobao.arthas.core.shell.term.impl.http.session; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.taobao.arthas.core.util.StringUtils; + +/** + * + * @author hengyunabc 2021-03-03 + * + */ +public class SimpleHttpSession implements HttpSession { + private Map attributes = new ConcurrentHashMap(); + + private String id; + + public SimpleHttpSession() { + id = StringUtils.randomString(32); + } + + @Override + public long getCreationTime() { + return 0; + } + + @Override + public String getId() { + return id; + } + + @Override + public long getLastAccessedTime() { + return 0; + } + + @Override + public void setMaxInactiveInterval(int interval) { + + } + + @Override + public int getMaxInactiveInterval() { + return 0; + } + + @Override + public Object getAttribute(String name) { + return attributes.get(name); + } + + @Override + public Enumeration getAttributeNames() { + return Collections.enumeration(this.attributes.keySet()); + } + + @Override + public void setAttribute(String name, Object value) { + attributes.put(name, value); + } + + @Override + public void removeAttribute(String name) { + attributes.remove(name); + } + + @Override + public void invalidate() { + + } + + @Override + public boolean isNew() { + return false; + } + +} diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java index f7de93789..97f52e434 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/HttpTelnetTermServer.java @@ -10,6 +10,7 @@ import com.taobao.arthas.core.shell.term.Term; import com.taobao.arthas.core.shell.term.TermServer; import com.taobao.arthas.core.shell.term.impl.Helper; import com.taobao.arthas.core.shell.term.impl.TermImpl; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; import io.netty.util.concurrent.EventExecutorGroup; import io.termd.core.function.Consumer; @@ -31,12 +32,14 @@ public class HttpTelnetTermServer extends TermServer { private int port; private long connectionTimeout; private EventExecutorGroup workerGroup; + private HttpSessionManager httpSessionManager; - public HttpTelnetTermServer(String hostIp, int port, long connectionTimeout, EventExecutorGroup workerGroup) { + public HttpTelnetTermServer(String hostIp, int port, long connectionTimeout, EventExecutorGroup workerGroup, HttpSessionManager httpSessionManager) { this.hostIp = hostIp; this.port = port; this.connectionTimeout = connectionTimeout; this.workerGroup = workerGroup; + this.httpSessionManager = httpSessionManager; } @Override @@ -48,7 +51,7 @@ public class HttpTelnetTermServer extends TermServer { @Override public TermServer listen(Handler> listenHandler) { // TODO: charset and inputrc from options - bootstrap = new NettyHttpTelnetTtyBootstrap(workerGroup).setHost(hostIp).setPort(port); + bootstrap = new NettyHttpTelnetTtyBootstrap(workerGroup, httpSessionManager).setHost(hostIp).setPort(port); try { bootstrap.start(new Consumer() { @Override diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java index 07644d9ee..95aa1b47b 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetBootstrap.java @@ -1,5 +1,7 @@ package com.taobao.arthas.core.shell.term.impl.httptelnet; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; + import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; @@ -31,11 +33,13 @@ public class NettyHttpTelnetBootstrap extends TelnetBootstrap { private EventLoopGroup group; private ChannelGroup channelGroup; private EventExecutorGroup workerGroup; + private HttpSessionManager httpSessionManager; - public NettyHttpTelnetBootstrap(EventExecutorGroup workerGroup) { + public NettyHttpTelnetBootstrap(EventExecutorGroup workerGroup, HttpSessionManager httpSessionManager) { this.workerGroup = workerGroup; this.group = new NioEventLoopGroup(new DefaultThreadFactory("arthas-NettyHttpTelnetBootstrap", true)); this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE); + this.httpSessionManager = httpSessionManager; } public NettyHttpTelnetBootstrap setHost(String host) { @@ -60,7 +64,7 @@ public class NettyHttpTelnetBootstrap extends TelnetBootstrap { .childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { - ch.pipeline().addLast(new ProtocolDetectHandler(channelGroup, handlerFactory, factory, workerGroup)); + ch.pipeline().addLast(new ProtocolDetectHandler(channelGroup, handlerFactory, factory, workerGroup, httpSessionManager)); } }); diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java index 05a7ec08a..f5b1b7bfd 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/NettyHttpTelnetTtyBootstrap.java @@ -2,6 +2,8 @@ package com.taobao.arthas.core.shell.term.impl.httptelnet; import java.nio.charset.Charset; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; + import io.netty.util.concurrent.EventExecutorGroup; import io.termd.core.function.Consumer; import io.termd.core.function.Supplier; @@ -22,8 +24,8 @@ public class NettyHttpTelnetTtyBootstrap { private boolean inBinary; private Charset charset = Charset.forName("UTF-8"); - public NettyHttpTelnetTtyBootstrap(EventExecutorGroup workerGroup) { - this.httpTelnetTtyBootstrap = new NettyHttpTelnetBootstrap(workerGroup); + public NettyHttpTelnetTtyBootstrap(EventExecutorGroup workerGroup, HttpSessionManager httpSessionManager) { + this.httpTelnetTtyBootstrap = new NettyHttpTelnetBootstrap(workerGroup, httpSessionManager); } public String getHost() { diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java index 8113ef9fc..7525fce12 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java @@ -1,11 +1,14 @@ package com.taobao.arthas.core.shell.term.impl.httptelnet; -import java.io.File; import java.util.concurrent.TimeUnit; +import com.taobao.arthas.common.ArthasConstants; +import com.taobao.arthas.core.shell.term.impl.http.BasicHttpAuthenticatorHandler; import com.taobao.arthas.core.shell.term.impl.http.HttpRequestHandler; import com.taobao.arthas.core.shell.term.impl.http.TtyWebSocketFrameHandler; +import com.taobao.arthas.core.shell.term.impl.http.session.HttpSessionManager; + import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -15,6 +18,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; import io.netty.handler.stream.ChunkedWriteHandler; +import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.ScheduledFuture; import io.termd.core.function.Consumer; @@ -33,13 +37,16 @@ public class ProtocolDetectHandler extends ChannelInboundHandlerAdapter { private Supplier handlerFactory; private Consumer ttyConnectionFactory; private EventExecutorGroup workerGroup; + private HttpSessionManager httpSessionManager; public ProtocolDetectHandler(ChannelGroup channelGroup, final Supplier handlerFactory, - Consumer ttyConnectionFactory, EventExecutorGroup workerGroup) { + Consumer ttyConnectionFactory, EventExecutorGroup workerGroup, + HttpSessionManager httpSessionManager) { this.channelGroup = channelGroup; this.handlerFactory = handlerFactory; this.ttyConnectionFactory = ttyConnectionFactory; this.workerGroup = workerGroup; + this.httpSessionManager = httpSessionManager; } private ScheduledFuture detectTelnetFuture; @@ -84,9 +91,11 @@ public class ProtocolDetectHandler extends ChannelInboundHandlerAdapter { } else { pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new ChunkedWriteHandler()); - pipeline.addLast(new HttpObjectAggregator(64 * 1024)); - pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File("arthas-output"))); - pipeline.addLast(new WebSocketServerProtocolHandler("/ws")); + pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH)); + pipeline.addLast(new BasicHttpAuthenticatorHandler(httpSessionManager)); + pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH)); + pipeline.addLast(new WebSocketServerProtocolHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH, true)); + pipeline.addLast(new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS)); pipeline.addLast(new TtyWebSocketFrameHandler(channelGroup, ttyConnectionFactory)); ctx.fireChannelActive(); } diff --git a/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java b/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java index 41b4dd044..1970ad059 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java @@ -114,6 +114,7 @@ public class ArthasBanner { .row("wiki", wiki()) .row("tutorials", tutorials()) .row("version", version()) + .row("main_class", PidUtils.mainClass()) .row("pid", PidUtils.currentPid()) .row("time", DateUtils.getCurrentDate()); for (Entry entry : infos.entrySet()) { diff --git a/core/src/main/java/com/taobao/arthas/core/util/ClassUtils.java b/core/src/main/java/com/taobao/arthas/core/util/ClassUtils.java index 437582e84..ff3fbe0b5 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ClassUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ClassUtils.java @@ -10,7 +10,7 @@ import java.util.Collection; import java.util.List; import java.util.Set; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; +import com.alibaba.deps.org.objectweb.asm.Type; import com.taobao.arthas.core.command.model.ClassDetailVO; import com.taobao.arthas.core.command.model.ClassLoaderVO; import com.taobao.arthas.core.command.model.ClassVO; @@ -181,7 +181,7 @@ public class ClassUtils { return list.toArray(new String[0]); } - public static List createClassVOList(Set> matchedClasses) { + public static List createClassVOList(Collection> matchedClasses) { List classVOs = new ArrayList(matchedClasses.size()); for (Class aClass : matchedClasses) { ClassVO classVO = createSimpleClassInfo(aClass); diff --git a/core/src/main/java/com/taobao/arthas/core/util/Decompiler.java b/core/src/main/java/com/taobao/arthas/core/util/Decompiler.java index 3707a90ba..aa9d10825 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/Decompiler.java +++ b/core/src/main/java/com/taobao/arthas/core/util/Decompiler.java @@ -5,9 +5,16 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NavigableMap; +import java.util.TreeMap; import org.benf.cfr.reader.api.CfrDriver; import org.benf.cfr.reader.api.OutputSinkFactory; +import org.benf.cfr.reader.api.SinkReturns.LineNumberMapping; + +import com.taobao.arthas.common.Pair; /** * @@ -20,24 +27,25 @@ public class Decompiler { return decompile(classFilePath, methodName, false); } - /** - * @param classFilePath - * @param methodName - * @param hideUnicode - * @return - */ public static String decompile(String classFilePath, String methodName, boolean hideUnicode) { - final StringBuilder result = new StringBuilder(8192); + return decompile(classFilePath, methodName, hideUnicode, true); + } + + public static Pair> decompileWithMappings(String classFilePath, + String methodName, boolean hideUnicode, boolean printLineNumber) { + final StringBuilder sb = new StringBuilder(8192); + + final NavigableMap lineMapping = new TreeMap(); OutputSinkFactory mySink = new OutputSinkFactory() { @Override public List getSupportedSinks(SinkType sinkType, Collection collection) { return Arrays.asList(SinkClass.STRING, SinkClass.DECOMPILED, SinkClass.DECOMPILED_MULTIVER, - SinkClass.EXCEPTION_MESSAGE); + SinkClass.EXCEPTION_MESSAGE, SinkClass.LINE_NUMBER_MAPPING); } @Override - public Sink getSink(final SinkType sinkType, SinkClass sinkClass) { + public Sink getSink(final SinkType sinkType, final SinkClass sinkClass) { return new Sink() { @Override public void write(T sinkable) { @@ -45,7 +53,19 @@ public class Decompiler { if (sinkType == SinkType.PROGRESS) { return; } - result.append(sinkable); + if (sinkType == SinkType.LINENUMBER) { + LineNumberMapping mapping = (LineNumberMapping) sinkable; + NavigableMap classFileMappings = mapping.getClassFileMappings(); + NavigableMap mappings = mapping.getMappings(); + if (classFileMappings != null && mappings != null) { + for (Entry entry : mappings.entrySet()) { + Integer srcLineNumber = classFileMappings.get(entry.getKey()); + lineMapping.put(entry.getValue(), srcLineNumber); + } + } + return; + } + sb.append(sinkable); } }; } @@ -58,6 +78,7 @@ public class Decompiler { */ options.put("showversion", "false"); options.put("hideutf", String.valueOf(hideUnicode)); + options.put("trackbytecodeloc", "true"); if (!StringUtils.isBlank(methodName)) { options.put("methodname", methodName); } @@ -67,7 +88,55 @@ public class Decompiler { toAnalyse.add(classFilePath); driver.analyse(toAnalyse); - return result.toString(); + String resultCode = sb.toString(); + if (printLineNumber && !lineMapping.isEmpty()) { + resultCode = addLineNumber(resultCode, lineMapping); + } + + return Pair.make(resultCode, lineMapping); + } + + public static String decompile(String classFilePath, String methodName, boolean hideUnicode, + boolean printLineNumber) { + return decompileWithMappings(classFilePath, methodName, hideUnicode, printLineNumber).getFirst(); + } + + private static String addLineNumber(String src, Map lineMapping) { + int maxLineNumber = 0; + for (Integer value : lineMapping.values()) { + if (value != null && value > maxLineNumber) { + maxLineNumber = value; + } + } + + String formatStr = "/*%2d*/ "; + String emptyStr = " "; + + StringBuilder sb = new StringBuilder(); + + List lines = StringUtils.toLines(src); + + if (maxLineNumber >= 100) { + formatStr = "/*%3d*/ "; + emptyStr = " "; + } else if (maxLineNumber >= 1000) { + formatStr = "/*%4d*/ "; + emptyStr = " "; + } + + int index = 0; + for (String line : lines) { + Integer srcLineNumber = lineMapping.get(index + 1); + if (srcLineNumber != null) { + sb.append(String.format(formatStr, srcLineNumber)); + } else { + sb.append(emptyStr); + } + sb.append(line).append("\n"); + index++; + } + + return sb.toString(); } } diff --git a/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java b/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java index c2aba4ad7..4b640b156 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/FileUtils.java @@ -158,8 +158,10 @@ public class FileUtils { try { out = new BufferedOutputStream(openOutputStream(file, false)); for (String command: history) { - out.write(command.getBytes("utf-8")); - out.write('\n'); + if (!StringUtils.isBlank(command)) { + out.write(command.getBytes("utf-8")); + out.write('\n'); + } } } catch (IOException e) { // ignore @@ -181,7 +183,9 @@ public class FileUtils { br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8")); String line; while ((line = br.readLine()) != null) { - history.add(line); + if (!StringUtils.isBlank(line)) { + history.add(line); + } } } catch (IOException e) { // ignore diff --git a/core/src/main/java/com/taobao/arthas/core/util/InstrumentationUtils.java b/core/src/main/java/com/taobao/arthas/core/util/InstrumentationUtils.java index 51b781a1f..3bcaa1c09 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/InstrumentationUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/InstrumentationUtils.java @@ -2,6 +2,7 @@ package com.taobao.arthas.core.util; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; +import java.util.Collection; import java.util.Set; import com.alibaba.arthas.deps.org.slf4j.Logger; @@ -38,4 +39,17 @@ public class InstrumentationUtils { inst.removeTransformer(transformer); } } + + public static void trigerRetransformClasses(Instrumentation inst, Collection classes) { + for (Class clazz : inst.getAllLoadedClasses()) { + if (classes.contains(clazz.getName())) { + try { + inst.retransformClasses(clazz); + } catch (Throwable e) { + String errorMsg = "retransformClasses class error, name: " + clazz.getName(); + logger.error(errorMsg, e); + } + } + } + } } diff --git a/core/src/main/java/com/taobao/arthas/core/util/LogUtil.java b/core/src/main/java/com/taobao/arthas/core/util/LogUtil.java index c9fd27ee9..f1e3c33cb 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/LogUtil.java +++ b/core/src/main/java/com/taobao/arthas/core/util/LogUtil.java @@ -68,7 +68,6 @@ public class LogUtil { loggerContext.reset(); String fileName = env.getProperty(FILE_NAME_PROPERTY); - ; if (fileName != null) { loggerContext.putProperty(ARTHAS_LOG_FILE, fileName); } diff --git a/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java b/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java index a3e9a63d1..f7be4f7ce 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/NetUtils.java @@ -22,6 +22,8 @@ public class NetUtils { private static final int QOS_PORT = 12201; private static final String QOS_RESPONSE_START_LINE = "pandora>[QOS Response]"; private static final int INTERNAL_SERVER_ERROR = 500; + private static final int CONNECT_TIMEOUT = 1000; + private static final int READ_TIMEOUT = 3000; /** * This implementation is based on Apache HttpClient. @@ -34,6 +36,8 @@ public class NetUtils { try { URL url = new URL(urlString); urlConnection = (HttpURLConnection)url.openConnection(); + urlConnection.setConnectTimeout(CONNECT_TIMEOUT); + urlConnection.setReadTimeout(READ_TIMEOUT);; // prefer json to text urlConnection.setRequestProperty("Accept", "application/json,text/plain;q=0.2"); in = urlConnection.getInputStream(); diff --git a/core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java b/core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java index bc8d8a2ef..82cddbafc 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java @@ -458,7 +458,7 @@ public abstract class ObjectUtils { sb.append(", "); } - sb.append(String.valueOf(array[i])); + sb.append(array[i]); } sb.append("}"); diff --git a/core/src/main/java/com/taobao/arthas/core/util/SearchUtils.java b/core/src/main/java/com/taobao/arthas/core/util/SearchUtils.java index 47f52de84..70623888a 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/SearchUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/SearchUtils.java @@ -31,6 +31,9 @@ public class SearchUtils { } final Set> matches = new HashSet>(); for (Class clazz : inst.getAllLoadedClasses()) { + if (clazz == null) { + continue; + } if (classNameMatcher.matching(clazz.getName())) { matches.add(clazz); } @@ -107,6 +110,9 @@ public class SearchUtils { public static Set> searchSubClass(Instrumentation inst, Set> classSet) { final Set> matches = new HashSet>(); for (Class clazz : inst.getAllLoadedClasses()) { + if (clazz == null) { + continue; + } for (Class superClass : classSet) { if (superClass.isAssignableFrom(clazz)) { matches.add(clazz); diff --git a/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java b/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java index 54c7974c2..b7700d71a 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/StringUtils.java @@ -1,14 +1,23 @@ package com.taobao.arthas.core.util; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; + public abstract class StringUtils { + private static final Logger logger = LoggerFactory.getLogger(StringUtils.class); + private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; /** * 获取异常的原因描述 @@ -36,7 +45,10 @@ public abstract class StringUtils { try { return obj.toString(); } catch (Throwable t) { - return "ERROR DATA!!! Method toString() throw exception. obj class: " + obj.getClass() + ", exception message: " + t.getMessage(); + logger.error("objectToString error, obj class: {}", obj.getClass(), t); + return "ERROR DATA!!! Method toString() throw exception. obj class: " + obj.getClass() + + ", exception class: " + t.getClass() + + ", exception message: " + t.getMessage(); } } @@ -449,10 +461,14 @@ public abstract class StringUtils { public static String replace(String inString, String oldPattern, String newPattern) { if(hasLength(inString) && hasLength(oldPattern) && newPattern != null) { - StringBuilder sb = new StringBuilder(); int pos = 0; int index = inString.indexOf(oldPattern); + if (index < 0) { + //no need to replace + return inString; + } + StringBuilder sb = new StringBuilder(); for(int patLen = oldPattern.length(); index >= 0; index = inString.indexOf(oldPattern, pos)) { sb.append(inString.substring(pos, index)); sb.append(newPattern); @@ -881,4 +897,75 @@ public abstract class StringUtils { : bytes < 0xfffccccccccccccL ? String.format("%.1f PiB", (bytes >> 10) / 0x1p40) : String.format("%.1f EiB", (bytes >> 20) / 0x1p40); } + + public static List toLines(String text) { + List result = new ArrayList(); + BufferedReader reader = new BufferedReader(new StringReader(text)); + try { + String line = reader.readLine(); + while (line != null) { + result.add(line); + line = reader.readLine(); + } + } catch (IOException exc) { + // quit + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + // ignore + } + } + } + return result; + } + + public static String randomString(int length) { + StringBuilder sb = new StringBuilder(length); + for (int i = 0; i < length; i++) + sb.append(AB.charAt(ThreadLocalRandom.current().nextInt(AB.length()))); + return sb.toString(); + } + + /** + * Returns the string before the given token + * + * @param text the text + * @param before the token + * @return the text before the token, or null if text does not contain + * the token + */ + public static String before(String text, String before) { + int pos = text.indexOf(before); + return pos == -1 ? null : text.substring(0, pos); + } + + /** + * Returns the string after the given token + * + * @param text the text + * @param after the token + * @return the text after the token, or null if text does not contain + * the token + */ + public static String after(String text, String after) { + int pos = text.indexOf(after); + if (pos == -1) { + return null; + } + return text.substring(pos + after.length()); + } + + public static String[] splitMethodInfo(String methodInfo) { + int index = methodInfo.indexOf('|'); + return new String[] { methodInfo.substring(0, index), methodInfo.substring(index + 1, methodInfo.length()) }; + } + + public static String[] splitInvokeInfo(String invokeInfo) { + int index1 = invokeInfo.indexOf('|'); + int index2 = invokeInfo.indexOf('|', index1 + 1); + return new String[] { invokeInfo.substring(0, index1), invokeInfo.substring(index1 + 1, index2), + invokeInfo.substring(index2 + 1, invokeInfo.length()) }; + } } diff --git a/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java b/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java index 1556516ff..f8f313f4b 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ThreadUtil.java @@ -36,29 +36,22 @@ abstract public class ThreadUtil { } /** - * 获取所有线程Map,以线程Name-ID为key - * - * @return + * 获取所有线程 */ - public static Map getThreads() { + public static List getThreads() { ThreadGroup root = getRoot(); Thread[] threads = new Thread[root.activeCount()]; while (root.enumerate(threads, true) == threads.length) { threads = new Thread[threads.length * 2]; } - SortedMap map = new TreeMap(new Comparator() { - @Override - public int compare(String o1, String o2) { - return o1.compareTo(o2); - } - }); + List list = new ArrayList(threads.length); for (Thread thread : threads) { if (thread != null) { ThreadVO threadVO = createThreadVO(thread); - map.put(thread.getName() + "-" + thread.getId(), threadVO); + list.add(threadVO); } } - return map; + return list; } private static ThreadVO createThreadVO(Thread thread) { @@ -215,8 +208,7 @@ abstract public class ThreadUtil { } sb.append('\n'); int i = 0; - for (; i < threadInfo.getStackTrace().length; i++) { - StackTraceElement ste = threadInfo.getStackTrace()[i]; + for (StackTraceElement ste : threadInfo.getStackTrace()) { sb.append("\tat ").append(ste.toString()); sb.append('\n'); if (i == 0 && threadInfo.getLockInfo() != null) { @@ -249,6 +241,7 @@ abstract public class ThreadUtil { sb.append('\n'); } } + ++i; } if (i < threadInfo.getStackTrace().length) { sb.append("\t..."); diff --git a/core/src/main/java/com/taobao/arthas/core/view/Ansi.java b/core/src/main/java/com/taobao/arthas/core/view/Ansi.java index 481b7d999..35c1d1ae9 100644 --- a/core/src/main/java/com/taobao/arthas/core/view/Ansi.java +++ b/core/src/main/java/com/taobao/arthas/core/view/Ansi.java @@ -59,8 +59,6 @@ public class Ansi { } } - ; - public static enum Attribute { RESET(0, "RESET"), INTENSITY_BOLD(1, "INTENSITY_BOLD"), @@ -100,8 +98,6 @@ public class Ansi { } - ; - public static enum Erase { FORWARD(0, "FORWARD"), BACKWARD(1, "BACKWARD"), @@ -125,8 +121,6 @@ public class Ansi { } } - ; - public static final String DISABLE = Ansi.class.getName() + ".disable"; private static Callable detector = new Callable() { diff --git a/core/src/main/java/com/taobao/arthas/core/view/ObjectView.java b/core/src/main/java/com/taobao/arthas/core/view/ObjectView.java index 3525f3ea8..baf80cbf1 100644 --- a/core/src/main/java/com/taobao/arthas/core/view/ObjectView.java +++ b/core/src/main/java/com/taobao/arthas/core/view/ObjectView.java @@ -1,5 +1,7 @@ package com.taobao.arthas.core.view; +import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.taobao.arthas.core.GlobalOptions; @@ -18,7 +20,7 @@ import static java.lang.String.format; * Created by vlinux on 15/5/20. */ public class ObjectView implements View { - + private static final Logger logger = LoggerFactory.getLogger(ObjectView.class); private final static int MAX_OBJECT_LENGTH = 10 * 1024 * 1024; // 10M private final Object object; @@ -50,7 +52,9 @@ public class ObjectView implements View { .append(", try to specify -M size_limit in your command, check the help command for more."); return buf.toString(); } catch (Throwable t) { - return "ERROR DATA!!! exception message: " + t.getMessage(); + logger.error("ObjectView draw error, object class: {}", object.getClass(), t); + return "ERROR DATA!!! object class: " + object.getClass() + ", exception class: " + t.getClass() + + ", exception message: " + t.getMessage(); } } @@ -583,7 +587,7 @@ public class ObjectView implements View { } else { appendStringBuilder(buf, format("@%s[", className)); List fields = new ArrayList(); - Class objClass = obj.getClass(); + Class objClass = obj.getClass(); if (GlobalOptions.printParentFields) { // 当父类为null的时候说明到达了最上层的父类(Object类). while (objClass != null) { diff --git a/core/src/main/resources/com/taobao/arthas/core/http/web-console.js b/core/src/main/resources/com/taobao/arthas/core/http/web-console.js index 7f9486643..a63efdf42 100644 --- a/core/src/main/resources/com/taobao/arthas/core/http/web-console.js +++ b/core/src/main/resources/com/taobao/arthas/core/http/web-console.js @@ -8,6 +8,8 @@ $(function () { if (ip != '' && ip != null) { $('#ip').val(ip); + } else { + $('#ip').val(window.location.hostname); } if (port != '' && port != null) { $('#port').val(port); diff --git a/core/src/test/java/com/taobao/arthas/core/advisor/EnhancerTest.java b/core/src/test/java/com/taobao/arthas/core/advisor/EnhancerTest.java index c514149f2..bbf97e466 100644 --- a/core/src/test/java/com/taobao/arthas/core/advisor/EnhancerTest.java +++ b/core/src/test/java/com/taobao/arthas/core/advisor/EnhancerTest.java @@ -2,23 +2,18 @@ package com.taobao.arthas.core.advisor; import java.arthas.SpyAPI; import java.lang.instrument.Instrumentation; -import java.util.HashSet; -import java.util.Set; -import java.util.jar.JarFile; import org.assertj.core.api.Assertions; import org.junit.Test; import org.mockito.Mockito; -import org.zeroturnaround.zip.ZipUtil; -import com.alibaba.arthas.deps.org.objectweb.asm.Type; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.Decompiler; +import com.alibaba.bytekit.utils.AsmUtils; +import com.alibaba.bytekit.utils.Decompiler; +import com.alibaba.deps.org.objectweb.asm.Type; +import com.alibaba.deps.org.objectweb.asm.tree.ClassNode; +import com.alibaba.deps.org.objectweb.asm.tree.MethodNode; import com.taobao.arthas.core.bytecode.TestHelper; import com.taobao.arthas.core.server.ArthasBootstrap; -import com.taobao.arthas.core.util.affect.EnhancerAffect; import com.taobao.arthas.core.util.matcher.EqualsMatcher; import demo.MathGame; @@ -44,7 +39,7 @@ public class EnhancerTest { EqualsMatcher methodNameMatcher = new EqualsMatcher("print"); EqualsMatcher classNameMatcher = new EqualsMatcher(MathGame.class.getName()); - Enhancer enhancer = new Enhancer(listener, true, false, classNameMatcher, methodNameMatcher); + Enhancer enhancer = new Enhancer(listener, true, false, classNameMatcher, null, methodNameMatcher); ClassLoader inClassLoader = MathGame.class.getClassLoader(); String className = MathGame.class.getName(); diff --git a/core/src/test/java/com/taobao/arthas/core/advisor/SpyImplTest.java b/core/src/test/java/com/taobao/arthas/core/advisor/SpyImplTest.java new file mode 100644 index 000000000..047d32f6f --- /dev/null +++ b/core/src/test/java/com/taobao/arthas/core/advisor/SpyImplTest.java @@ -0,0 +1,28 @@ +package com.taobao.arthas.core.advisor; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import com.taobao.arthas.core.util.StringUtils; + +/** + * + * @author hengyunabc 2021-07-14 + * + */ +public class SpyImplTest { + + @Test + public void testSplitMethodInfo() throws Throwable { + Assertions.assertThat(StringUtils.splitMethodInfo("a|b")).containsExactly("a", "b"); + Assertions.assertThat(StringUtils.splitMethodInfo("xxxxxxxxxx|fffffffffff")).containsExactly("xxxxxxxxxx", + "fffffffffff"); + } + + @Test + public void testSplitInvokeInfo() throws Throwable { + Assertions.assertThat(StringUtils.splitInvokeInfo("a|b|c")).containsExactly("a", "b", "c"); + Assertions.assertThat(StringUtils.splitInvokeInfo("xxxxxxxxxx|fffffffffff|yyy")).containsExactly("xxxxxxxxxx", + "fffffffffff", "yyy"); + } +} diff --git a/core/src/test/java/com/taobao/arthas/core/bytecode/TestHelper.java b/core/src/test/java/com/taobao/arthas/core/bytecode/TestHelper.java index d5f9a19a4..059647424 100644 --- a/core/src/test/java/com/taobao/arthas/core/bytecode/TestHelper.java +++ b/core/src/test/java/com/taobao/arthas/core/bytecode/TestHelper.java @@ -9,16 +9,16 @@ import java.util.jar.JarFile; import org.zeroturnaround.zip.ZipUtil; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; -import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; - -import com.taobao.arthas.bytekit.asm.MethodProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; -import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; -import com.taobao.arthas.bytekit.utils.AgentUtils; -import com.taobao.arthas.bytekit.utils.AsmUtils; -import com.taobao.arthas.bytekit.utils.MatchUtils; -import com.taobao.arthas.bytekit.utils.VerifyUtils; +import com.alibaba.deps.org.objectweb.asm.tree.ClassNode; +import com.alibaba.deps.org.objectweb.asm.tree.MethodNode; + +import com.alibaba.bytekit.asm.MethodProcessor; +import com.alibaba.bytekit.asm.interceptor.InterceptorProcessor; +import com.alibaba.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; +import com.alibaba.bytekit.utils.AgentUtils; +import com.alibaba.bytekit.utils.AsmUtils; +import com.alibaba.bytekit.utils.MatchUtils; +import com.alibaba.bytekit.utils.VerifyUtils; /** * diff --git a/core/src/test/java/com/taobao/arthas/core/security/SecurityAuthenticatorImplTest.java b/core/src/test/java/com/taobao/arthas/core/security/SecurityAuthenticatorImplTest.java new file mode 100644 index 000000000..07bd91fe0 --- /dev/null +++ b/core/src/test/java/com/taobao/arthas/core/security/SecurityAuthenticatorImplTest.java @@ -0,0 +1,40 @@ +package com.taobao.arthas.core.security; + +import java.security.Principal; + +import javax.security.auth.Subject; +import javax.security.auth.login.LoginException; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +/** + * + * @author hengyunabc 2021-03-04 + * + */ +public class SecurityAuthenticatorImplTest { + + @Test + public void test1() throws LoginException { + String username = "test"; + String password = "ppp"; + SecurityAuthenticatorImpl auth = new SecurityAuthenticatorImpl(username, password); + + Assertions.assertThat(auth.needLogin()).isTrue(); + + Principal principal = new BasicPrincipal(username, password); + Subject subject = auth.login(principal); + + Assertions.assertThat(subject).isNotNull(); + } + + @Test + public void test2() { + String username = "test"; + String password = null; + SecurityAuthenticatorImpl auth = new SecurityAuthenticatorImpl(username, password); + Assertions.assertThat(auth.needLogin()).isTrue(); + } + +} diff --git a/core/src/test/java/com/taobao/arthas/core/server/ArthasBootstrapTest.java b/core/src/test/java/com/taobao/arthas/core/server/ArthasBootstrapTest.java new file mode 100644 index 000000000..93ea81f27 --- /dev/null +++ b/core/src/test/java/com/taobao/arthas/core/server/ArthasBootstrapTest.java @@ -0,0 +1,103 @@ +package com.taobao.arthas.core.server; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.lang.instrument.Instrumentation; + +import org.jboss.modules.ModuleClassLoader; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.FieldSetter; + +import com.taobao.arthas.common.JavaVersionUtils; +import com.taobao.arthas.core.bytecode.TestHelper; +import com.taobao.arthas.core.config.Configure; +import com.taobao.arthas.core.env.ArthasEnvironment; + +import net.bytebuddy.agent.ByteBuddyAgent; + +/** + * + * @author hengyunabc 2020-12-02 + * + */ +public class ArthasBootstrapTest { + @Before + public void beforeMethod() { + // jboss modules need jdk8 + org.junit.Assume.assumeTrue(JavaVersionUtils.isGreaterThanJava7()); + } + + @Test + public void test() throws Exception { + Instrumentation instrumentation = ByteBuddyAgent.install(); + TestHelper.appendSpyJar(instrumentation); + + ArthasBootstrap arthasBootstrap = Mockito.mock(ArthasBootstrap.class); + Mockito.doCallRealMethod().when(arthasBootstrap).enhanceClassLoader(); + + Configure configure = Mockito.mock(Configure.class); + Mockito.when(configure.getEnhanceLoaders()) + .thenReturn("java.lang.ClassLoader,org.jboss.modules.ConcurrentClassLoader"); + FieldSetter.setField(arthasBootstrap, ArthasBootstrap.class.getDeclaredField("configure"), configure); + FieldSetter.setField(arthasBootstrap, ArthasBootstrap.class.getDeclaredField("instrumentation"), + instrumentation); + + org.jboss.modules.ModuleClassLoader moduleClassLoader = Mockito.mock(ModuleClassLoader.class); + + boolean flag = false; + try { + moduleClassLoader.loadClass("java.arthas.SpyAPI"); + } catch (Exception e) { + flag = true; + } + assertThat(flag).isTrue(); + + arthasBootstrap.enhanceClassLoader(); + + Class loadClass = moduleClassLoader.loadClass("java.arthas.SpyAPI"); + + System.err.println(loadClass); + + } + + @Test + public void testConfigLocationNull() throws Exception { + ArthasEnvironment arthasEnvironment = new ArthasEnvironment(); + String location = ArthasBootstrap.reslove(arthasEnvironment, ArthasBootstrap.CONFIG_LOCATION_PROPERTY, null); + assertThat(location).isEqualTo(null); + } + + @Test + public void testConfigLocation() throws Exception { + ArthasEnvironment arthasEnvironment = new ArthasEnvironment(); + + System.setProperty("hhhh", "fff"); + System.setProperty(ArthasBootstrap.CONFIG_LOCATION_PROPERTY, "test${hhhh}"); + + String location = ArthasBootstrap.reslove(arthasEnvironment, ArthasBootstrap.CONFIG_LOCATION_PROPERTY, null); + System.clearProperty("hhhh"); + System.clearProperty(ArthasBootstrap.CONFIG_LOCATION_PROPERTY); + + assertThat(location).isEqualTo("test" + "fff"); + } + + @Test + public void testConfigNameDefault() throws Exception { + ArthasEnvironment arthasEnvironment = new ArthasEnvironment(); + + String configName = ArthasBootstrap.reslove(arthasEnvironment, ArthasBootstrap.CONFIG_NAME_PROPERTY, "arthas"); + assertThat(configName).isEqualTo("arthas"); + } + + @Test + public void testConfigName() throws Exception { + ArthasEnvironment arthasEnvironment = new ArthasEnvironment(); + + System.setProperty(ArthasBootstrap.CONFIG_NAME_PROPERTY, "testName"); + String configName = ArthasBootstrap.reslove(arthasEnvironment, ArthasBootstrap.CONFIG_NAME_PROPERTY, "arthas"); + System.clearProperty(ArthasBootstrap.CONFIG_NAME_PROPERTY); + assertThat(configName).isEqualTo("testName"); + } +} diff --git a/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java b/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java index 593a0d688..e739a4eb5 100644 --- a/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java +++ b/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java @@ -13,16 +13,18 @@ public class DateUtilsTest { @Test public void testGetCurrentDateWithCorrectFormat() { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //supported date format - Assert.assertEquals(DateUtils.getCurrentDate(),dateFormat.format(new Date()).toString()); - + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // supported date format + Date date = new Date(); + Assert.assertEquals(DateUtils.formatDate(date), dateFormat.format(date).toString()); + } @Test public void testGetCurrentDateWithInCorrectFormat() { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Not supported Date format - Assert.assertNotEquals(DateUtils.getCurrentDate(),dateFormat.format(new Date()).toString()); - + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Not supported Date format + Date date = new Date(); + Assert.assertNotEquals(DateUtils.formatDate(date), dateFormat.format(date).toString()); + } } \ No newline at end of file diff --git a/core/src/test/java/com/taobao/arthas/core/util/DecompilerTest.java b/core/src/test/java/com/taobao/arthas/core/util/DecompilerTest.java new file mode 100644 index 000000000..43e773a9a --- /dev/null +++ b/core/src/test/java/com/taobao/arthas/core/util/DecompilerTest.java @@ -0,0 +1,37 @@ +package com.taobao.arthas.core.util; + +import java.io.File; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +/** + * + * @author hengyunabc 2021-02-09 + * + */ +public class DecompilerTest { + + @Test + public void test() { + String dir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); + + File classFile = new File(dir, this.getClass().getName().replace('.', '/') + ".class"); + + String code = Decompiler.decompile(classFile.getAbsolutePath(), null, true); + + System.err.println(code); + + Assertions.assertThat(code).contains("/*23*/ System.err.println(code);").contains("/*32*/ int i = 0;"); + } + + public void aaa() { + + int jjj = 0; + + for (int i = 0; i < 100; ++i) { + System.err.println(i); + } + } + +} diff --git a/core/src/test/java/com/taobao/arthas/core/util/LogUtilTest.java b/core/src/test/java/com/taobao/arthas/core/util/LogUtilTest.java index 483497395..8cb3d153f 100644 --- a/core/src/test/java/com/taobao/arthas/core/util/LogUtilTest.java +++ b/core/src/test/java/com/taobao/arthas/core/util/LogUtilTest.java @@ -1,6 +1,7 @@ package com.taobao.arthas.core.util; import java.io.File; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Properties; @@ -72,11 +73,10 @@ public class LogUtilTest { } @Test - public void test_DefaultLogFile() throws URISyntaxException { + public void test_DefaultLogFile() throws URISyntaxException, IOException { Properties properties1 = new Properties(); properties1.put("arthas.home", testResourcesDir); - - String logFile = new File(System.getProperty("user.home"), "logs/arthas/arthas.log").getAbsolutePath(); + String logFile = new File(System.getProperty("user.home"), "logs/arthas/arthas.log").getCanonicalPath(); arthasEnvironment.addLast(new PropertiesPropertySource("test1", properties1)); @@ -95,7 +95,7 @@ public class LogUtilTest { if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; String file = fileAppender.getFile(); - Assertions.assertThat(file).isEqualTo(logFile); + Assertions.assertThat(new File(file).getCanonicalPath()).isEqualTo(logFile); foundFileAppender = true; } } @@ -103,11 +103,11 @@ public class LogUtilTest { } @Test - public void test_ARTHAS_LOG_FILE() throws URISyntaxException { + public void test_ARTHAS_LOG_FILE() throws URISyntaxException, IOException { Properties properties1 = new Properties(); properties1.put("arthas.home", testResourcesDir); - String logFile = new File(tempFolder.getRoot().getAbsoluteFile(), "test.log").getAbsolutePath(); + String logFile = new File(tempFolder.getRoot().getAbsoluteFile(), "test.log").getCanonicalPath(); properties1.put(LogUtil.FILE_NAME_PROPERTY, logFile); arthasEnvironment.addLast(new PropertiesPropertySource("test1", properties1)); @@ -127,7 +127,7 @@ public class LogUtilTest { if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; String file = fileAppender.getFile(); - Assertions.assertThat(file).isEqualTo(logFile); + Assertions.assertThat(new File(file).getCanonicalPath()).isEqualTo(logFile); foundFileAppender = true; } } @@ -135,11 +135,11 @@ public class LogUtilTest { } @Test - public void test_ARTHAS_LOG_PATH() throws URISyntaxException { + public void test_ARTHAS_LOG_PATH() throws URISyntaxException, IOException { Properties properties1 = new Properties(); properties1.put("arthas.home", testResourcesDir); - String logFile = new File(tempFolder.getRoot().getAbsoluteFile(), "arthas.log").getAbsolutePath(); + String logFile = new File(tempFolder.getRoot().getAbsoluteFile(), "arthas.log").getCanonicalPath(); properties1.put(LogUtil.FILE_PATH_PROPERTY, tempFolder.getRoot().getAbsolutePath()); arthasEnvironment.addLast(new PropertiesPropertySource("test1", properties1)); @@ -159,7 +159,7 @@ public class LogUtilTest { if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; String file = fileAppender.getFile(); - Assertions.assertThat(file).isEqualTo(logFile); + Assertions.assertThat(new File(file).getCanonicalPath()).isEqualTo(logFile); foundFileAppender = true; } } diff --git a/core/src/test/java/com/taobao/arthas/core/util/TypeRenderUtilsTest.java b/core/src/test/java/com/taobao/arthas/core/util/TypeRenderUtilsTest.java index f90f93e6e..2baa2e295 100644 --- a/core/src/test/java/com/taobao/arthas/core/util/TypeRenderUtilsTest.java +++ b/core/src/test/java/com/taobao/arthas/core/util/TypeRenderUtilsTest.java @@ -1,7 +1,10 @@ package com.taobao.arthas.core.util; +import org.assertj.core.api.Assertions; import org.junit.Test; +import com.taobao.arthas.common.JavaVersionUtils; + import java.io.Serializable; import static org.hamcrest.CoreMatchers.equalTo; @@ -26,7 +29,14 @@ public class TypeRenderUtilsTest { @Test public void testDrawInterface() { - assertThat(TypeRenderUtils.drawInterface(String.class), is(equalTo("java.io.Serializable,java.lang.Comparable,java.lang.CharSequence"))); + if (JavaVersionUtils.isGreaterThanJava11()) { + Assertions.assertThat(TypeRenderUtils.drawInterface(String.class)).isEqualTo( + "java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,java.lang.constant.Constable,java.lang.constant.ConstantDesc"); + } else { + Assertions.assertThat(TypeRenderUtils.drawInterface(String.class)) + .isEqualTo("java.io.Serializable,java.lang.Comparable,java.lang.CharSequence"); + } + assertThat(TypeRenderUtils.drawInterface(TestClass.class), is(equalTo("java.io.Serializable"))); assertThat(TypeRenderUtils.drawInterface(Serializable.class), is(equalTo(""))); } diff --git a/lib/libArthasJniLibrary-x64.dll b/lib/libArthasJniLibrary-x64.dll new file mode 100644 index 000000000..ac42d1ad2 Binary files /dev/null and b/lib/libArthasJniLibrary-x64.dll differ diff --git a/lib/libArthasJniLibrary-x64.dylib b/lib/libArthasJniLibrary-x64.dylib new file mode 100644 index 000000000..f1e977585 Binary files /dev/null and b/lib/libArthasJniLibrary-x64.dylib differ diff --git a/lib/libArthasJniLibrary-x64.so b/lib/libArthasJniLibrary-x64.so new file mode 100644 index 000000000..bd4edc7b3 Binary files /dev/null and b/lib/libArthasJniLibrary-x64.so differ diff --git a/demo/pom.xml b/math-game/pom.xml similarity index 84% rename from demo/pom.xml rename to math-game/pom.xml index 5f9b77b30..1beaedf2a 100644 --- a/demo/pom.xml +++ b/math-game/pom.xml @@ -1,17 +1,17 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml - arthas-demo - arthas-demo + math-game + math-game - arthas-demo + math-game org.apache.maven.plugins diff --git a/demo/src/main/java/demo/MathGame.java b/math-game/src/main/java/demo/MathGame.java similarity index 97% rename from demo/src/main/java/demo/MathGame.java rename to math-game/src/main/java/demo/MathGame.java index 7f63b1660..82466227f 100644 --- a/demo/src/main/java/demo/MathGame.java +++ b/math-game/src/main/java/demo/MathGame.java @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit; public class MathGame { private static Random random = new Random(); - public int illegalArgumentCount = 0; + private int illegalArgumentCount = 0; public static void main(String[] args) throws InterruptedException { MathGame game = new MathGame(); diff --git a/memorycompiler/pom.xml b/memorycompiler/pom.xml index b9089495b..b239fde91 100644 --- a/memorycompiler/pom.xml +++ b/memorycompiler/pom.xml @@ -1,23 +1,16 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-memorycompiler arthas-memorycompiler - - commons-io - commons-io - 2.6 - test - - org.slf4j slf4j-api diff --git a/memorycompiler/src/test/java/com/taobao/arthas/compiler/DynamicCompilerTest.java b/memorycompiler/src/test/java/com/taobao/arthas/compiler/DynamicCompilerTest.java index 46348feaa..fe6d064fc 100644 --- a/memorycompiler/src/test/java/com/taobao/arthas/compiler/DynamicCompilerTest.java +++ b/memorycompiler/src/test/java/com/taobao/arthas/compiler/DynamicCompilerTest.java @@ -1,14 +1,14 @@ package com.taobao.arthas.compiler; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.net.URLClassLoader; -import java.nio.charset.Charset; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; import org.slf4j.LoggerFactory; @@ -33,8 +33,8 @@ public class DynamicCompilerTest { InputStream logger1Stream = DynamicCompilerTest.class.getClassLoader().getResourceAsStream("TestLogger1.java"); InputStream logger2Stream = DynamicCompilerTest.class.getClassLoader().getResourceAsStream("TestLogger2.java"); - dynamicCompiler.addSource("TestLogger2", IOUtils.toString(logger2Stream, Charset.defaultCharset())); - dynamicCompiler.addSource("TestLogger1", IOUtils.toString(logger1Stream, Charset.defaultCharset())); + dynamicCompiler.addSource("TestLogger2", toString(logger2Stream)); + dynamicCompiler.addSource("TestLogger1", toString(logger1Stream)); Map byteCodes = dynamicCompiler.buildByteCodes(); @@ -42,4 +42,36 @@ public class DynamicCompilerTest { Assert.assertTrue("TestLogger2", byteCodes.containsKey("com.hello.TestLogger2")); } + /** + * Get the contents of an InputStream as a String + * using the default character encoding of the platform. + *

+ * This method buffers the input internally, so there is no need to use a + * BufferedInputStream. + * + * @param input the InputStream to read from + * @return the requested String + * @throws NullPointerException if the input is null + * @throws IOException if an I/O error occurs + */ + public static String toString(InputStream input) throws IOException { + BufferedReader br = null; + try { + StringBuilder sb = new StringBuilder(); + br = new BufferedReader(new InputStreamReader(input)); + String line; + while ((line = br.readLine()) != null) { + sb.append(line).append("\n"); + } + return sb.toString(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + // ignore + } + } + } + } } diff --git a/mvnw b/mvnw index 5551fde8e..41c0f0c23 100755 --- a/mvnw +++ b/mvnw @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven2 Start Up Batch script +# Maven Start Up Batch script # # Required ENV vars: # ------------------ @@ -114,7 +114,6 @@ if $mingw ; then M2_HOME="`(cd "$M2_HOME"; pwd)`" [ -n "$JAVA_HOME" ] && JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" - # TODO classpath? fi if [ -z "$JAVA_HOME" ]; then @@ -212,7 +211,11 @@ else if [ "$MVNW_VERBOSE" = true ]; then echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." fi - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi while IFS="=" read key value; do case "$key" in (wrapperUrl) jarUrl="$value"; break ;; esac @@ -221,22 +224,38 @@ else echo "Downloading from: $jarUrl" fi wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi if command -v wget > /dev/null; then if [ "$MVNW_VERBOSE" = true ]; then echo "Found wget ... using wget" fi - wget "$jarUrl" -O "$wrapperJarPath" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi elif command -v curl > /dev/null; then if [ "$MVNW_VERBOSE" = true ]; then echo "Found curl ... using curl" fi - curl -o "$wrapperJarPath" "$jarUrl" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + else if [ "$MVNW_VERBOSE" = true ]; then echo "Falling back to using Java to download" fi javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi if [ -e "$javaClass" ]; then if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then if [ "$MVNW_VERBOSE" = true ]; then @@ -277,6 +296,11 @@ if $cygwin; then MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` fi +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain exec "$JAVACMD" \ diff --git a/mvnw.cmd b/mvnw.cmd old mode 100755 new mode 100644 index 48363fa60..86115719e --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,161 +1,182 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven2 Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" -FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - echo Found %WRAPPER_JAR% -) else ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" - echo Finished downloading %WRAPPER_JAR% -) -@REM End of extension - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/packaging/pom.xml b/packaging/pom.xml index 5d91628f8..1d8e7fe78 100644 --- a/packaging/pom.xml +++ b/packaging/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-packaging @@ -157,6 +157,9 @@ linux + + rpm + diff --git a/packaging/src/main/assembly/assembly.xml b/packaging/src/main/assembly/assembly.xml index 1f2810a83..121523e78 100644 --- a/packaging/src/main/assembly/assembly.xml +++ b/packaging/src/main/assembly/assembly.xml @@ -38,8 +38,8 @@ arthas-boot.jar - ../demo/target/arthas-demo.jar - arthas-demo.jar + ../math-game/target/math-game.jar + math-game.jar @@ -63,5 +63,8 @@ ../async-profiler + + ../lib + diff --git a/pom.xml b/pom.xml index cdd704da7..4bf542bbf 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 @@ -21,7 +21,7 @@ scm:git:git@github.com:alibaba/arthas.git https://github.com/alibaba/arthas HEAD - + @@ -48,7 +48,7 @@ com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} pom arthas-all @@ -56,10 +56,12 @@ https://github.com/alibaba/arthas - spy + math-game common + spy + arthas-vmtool + tunnel-common tunnel-client - bytekit core agent client @@ -67,60 +69,13 @@ boot arthas-agent-attach arthas-spring-boot-starter - demo testcase site packaging - - - jdk8 - - [1.8,) - - - tunnel-server - - - - - - pl.project13.maven - git-commit-id-plugin - 4.0.1 - - - - revision - - - - - false - yyyy-MM-dd'T'HH:mm:ssZ - true - ${project.build.outputDirectory}/arthas-git.properties - - git.build.host - git.build.time - git.build.user.email - git.build.user.name - git.remote.origin.url - git.total.commit.count - git.commit.time - git.local.branch.ahead - git.local.branch.behind - - true - - - - - - - + 3.5.2 UTF-8 1.6 1.6 @@ -128,19 +83,26 @@ 3.0.0 ${skipTests} 2020-09-27T15:10:43Z + 1.0.0 + 4.1.59.Final + + com.alibaba + bytekit-core + 0.0.7 + org.benf cfr - 0.150 + 0.151 com.alibaba.middleware termd-core - 1.1.7.10 + 1.1.7.11 com.alibaba.middleware @@ -150,7 +112,7 @@ org.slf4j slf4j-api - 1.7.25 + 1.7.31 ch.qos.logback @@ -165,17 +127,12 @@ com.alibaba.arthas arthas-repackage-logger - 0.0.6 - - - com.alibaba.arthas - arthas-repackage-asm - 0.0.6 + 0.0.9 com.alibaba fastjson - 1.2.71 + 1.2.75 com.taobao.text @@ -195,7 +152,7 @@ junit junit - 4.11 + 4.13.1 test @@ -214,27 +171,27 @@ io.netty netty-common - 4.1.46.Final + ${netty.version} io.netty netty-buffer - 4.1.46.Final + ${netty.version} io.netty netty-handler - 4.1.46.Final + ${netty.version} io.netty netty-transport - 4.1.46.Final + ${netty.version} io.netty netty-codec-http - 4.1.46.Final + ${netty.version} @@ -246,13 +203,13 @@ net.bytebuddy byte-buddy - 1.10.13 + 1.11.6 net.bytebuddy byte-buddy-agent - 1.10.13 + 1.11.6 @@ -263,6 +220,129 @@ + + + jdk8 + + [1.8,) + + + tunnel-server + + + + + + pl.project13.maven + git-commit-id-plugin + 4.0.1 + + + + revision + + + + + false + yyyy-MM-dd'T'HH:mm:ssZ + true + ${project.build.outputDirectory}/arthas-git.properties + + git.branch + git.build.host + git.build.time + git.build.user.email + git.build.user.name + git.remote.origin.url + git.total.commit.count + git.commit.time + git.local.branch.ahead + git.local.branch.behind + git.tags + + true + + + + + + + + + jdk12 + + [12,) + + JAVA8_HOME + + + + + com.sun + tools + 1.6.0 + system + ${JAVA8_HOME}/lib/tools.jar + + + + + + full + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + none + 1.8 + false + + + + release + package + + jar + + + + + + + + + + release + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + @@ -286,6 +366,59 @@ maven-antrun-plugin 1.8 + + + org.eclipse.m2e + lifecycle-mapping + ${lifecycle-mapping.version} + + + + + + + org.apache.maven.plugins + + + maven-invoker-plugin + + + [1.0.0,) + + + + install + + + + + + + + + + + org.codehaus.mojo + + + flatten-maven-plugin + + + [1.0.0,) + + + flatten + + + + + + + + + + @@ -303,14 +436,6 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - -Xdoclint:none - - org.apache.maven.plugins @@ -326,10 +451,35 @@ + + org.codehaus.mojo + flatten-maven-plugin + 1.2.2 + + minimum + + + + flatten + process-resources + + flatten + + + + flatten-clean + clean + + clean + + + + + org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.5 jacoco-initialize @@ -340,7 +490,6 @@ com/taobao/arthas/core/view/ObjectViewTest* com/taobao/arthas/core/model/ObjectRenderTest* - com/taobao/arthas/bytekit/asm/interceptor* diff --git a/site/pom.xml b/site/pom.xml index 2afa320d4..bf9b8cea4 100644 --- a/site/pom.xml +++ b/site/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-site diff --git a/site/src/site/sphinx/_include_html/arthas-tutorials.html b/site/src/site/sphinx/_include_html/arthas-tutorials.html index a4bb1efb6..95cff06fd 100644 --- a/site/src/site/sphinx/_include_html/arthas-tutorials.html +++ b/site/src/site/sphinx/_include_html/arthas-tutorials.html @@ -479,6 +479,18 @@ cn: "command-vmoption-cn", } }, + { + id: "command-vmtool", + type: "COMMAND-SYSTEM", + names: { + en: "vmtool", + cn: "vmtool", + }, + ids: { + en: "command-vmtool-en", + cn: "command-vmtool-cn", + } + }, { id: "command-perfcounter", type: "COMMAND-SYSTEM", @@ -587,6 +599,18 @@ cn: "command-jad-cn", } }, + { + id: "command-mc-retransform", + type: "COMMAND-CLASS", + names: { + en: "mc-retransform", + cn: "mc-retransform", + }, + ids: { + en: "command-mc-retransform-en", + cn: "command-mc-retransform-cn", + } + }, { id: "command-mc-redefine", type: "COMMAND-CLASS", @@ -743,6 +767,18 @@ cn: "case-watch-method-exception-cn", } }, + { + id: "case-ognl-practise", + type: "USERCASE", + names: { + en: "Debug ognl express", + cn: "调试ognl表达式", + }, + ids: { + en: "case-ognl-practise-en", + cn: "case-ognl-practise-cn", + } + }, { id: "case-thread", type: "USERCASE", diff --git a/site/src/site/sphinx/_static/dingding2_qr.jpg b/site/src/site/sphinx/_static/dingding2_qr.jpg index b34fcc452..2925dd026 100644 Binary files a/site/src/site/sphinx/_static/dingding2_qr.jpg and b/site/src/site/sphinx/_static/dingding2_qr.jpg differ diff --git a/site/src/site/sphinx/_static/dingding_qr.jpg b/site/src/site/sphinx/_static/dingding_qr.jpg index 9cd85c28e..d77ad7430 100644 Binary files a/site/src/site/sphinx/_static/dingding_qr.jpg and b/site/src/site/sphinx/_static/dingding_qr.jpg differ diff --git a/site/src/site/sphinx/_static/overrides.css b/site/src/site/sphinx/_static/overrides.css index 9c45d5b46..69c456020 100644 --- a/site/src/site/sphinx/_static/overrides.css +++ b/site/src/site/sphinx/_static/overrides.css @@ -1,6 +1,6 @@ @import url('https://g.alicdn.com/code/lib/github-fork-ribbon-css/0.1.1/gh-fork-ribbon.min.css'); -@import url('https://fonts.loli.net/css?family=Source+Sans+Pro:400,400i,700,700i'); -@import url('https://fonts.loli.net/css?family=Inconsolata:400,700'); +/* @import url('https://fonts.loli.net/css?family=Source+Sans+Pro:400,400i,700,700i'); */ +/* @import url('https://fonts.loli.net/css?family=Inconsolata:400,700'); */ html, body, .wy-grid-for-nav { font-family: 'Source Sans Pro', 'Helvetica', 'Arial', sans-serif; diff --git a/site/src/site/sphinx/_static/qqgroup2_qr.jpg b/site/src/site/sphinx/_static/qqgroup2_qr.jpg new file mode 100644 index 000000000..b4d7fd8c9 Binary files /dev/null and b/site/src/site/sphinx/_static/qqgroup2_qr.jpg differ diff --git a/site/src/site/sphinx/_static/qrcode_gongzhonghao.jpg b/site/src/site/sphinx/_static/qrcode_gongzhonghao.jpg new file mode 100644 index 000000000..9d0e54ab8 Binary files /dev/null and b/site/src/site/sphinx/_static/qrcode_gongzhonghao.jpg differ diff --git a/site/src/site/sphinx/advanced-use.md b/site/src/site/sphinx/advanced-use.md index b751cc77e..c17df1986 100644 --- a/site/src/site/sphinx/advanced-use.md +++ b/site/src/site/sphinx/advanced-use.md @@ -8,6 +8,7 @@ * [cat](cat.md)——打印文件内容,和linux里的cat命令类似 * [echo](echo.md)--打印参数,和linux里的echo命令类似 * [grep](grep.md)——匹配查找,和linux里的grep命令类似 +* [base64](base64.md)——base64编码转换,和linux里的base64命令类似 * [tee](tee.md)——复制标准输入到标准输出和指定的文件,和linux里的tee命令类似 * [pwd](pwd.md)——返回当前的工作目录,和linux命令类似 * cls——清空当前屏幕区域 @@ -34,7 +35,7 @@ * [ognl](ognl.md)——执行ognl表达式 * [mbean](mbean.md)——查看 Mbean 的信息 * [heapdump](heapdump.md)——dump java heap, 类似jmap命令的heap dump功能 - +* [vmtool](vmtool.md)——从jvm里查询对象,执行forceGc ## class/classloader相关 @@ -42,6 +43,7 @@ * [sm](sm.md)——查看已加载类的方法信息 * [jad](jad.md)——反编译指定已加载类的源码 * [mc](mc.md)——内存编译器,内存编译`.java`文件为`.class`文件 +* [retransform](retransform.md)——加载外部的`.class`文件,retransform到JVM里 * [redefine](redefine.md)——加载外部的`.class`文件,redefine到JVM里 * [dump](dump.md)——dump 已加载类的 byte code 到特定目录 * [classloader](classloader.md)——查看classloader的继承树,urls,类加载信息,使用classloader去getResource @@ -62,6 +64,9 @@ * [profiler](profiler.md)--使用[async-profiler](https://github.com/jvm-profiling-tools/async-profiler)对应用采样,生成火焰图 +## 鉴权 + +* [auth](auth.md)--鉴权 ## options * [options](options.md)——查看或设置Arthas全局开关 @@ -106,18 +111,18 @@ Arthas支持使用管道对上述命令的结果进行进一步的处理,如`s 正常情况下,每次执行`as.sh`/`arthas-boot.jar`需要选择,或者指定PID。这样会比较麻烦,因为每次启动应用,它的PID会变化。 -比如,已经启动了`arthas-demo.jar`,使用`jps`命令查看: +比如,已经启动了`math-game.jar`,使用`jps`命令查看: ```bash $ jps -58883 arthas-demo.jar +58883 math-game.jar 58884 Jps ``` 通过`select`参数可以指定进程名字,非常方便。 ```bash -$ ./as.sh --select arthas-demo +$ ./as.sh --select math-game Arthas script version: 3.3.6 [INFO] JAVA_HOME: /tmp/java/8.0.222-zulu Arthas home: /Users/admin/.arthas/lib/3.3.6/arthas diff --git a/site/src/site/sphinx/agent.md b/site/src/site/sphinx/agent.md index a606e75e6..e11f82577 100644 --- a/site/src/site/sphinx/agent.md +++ b/site/src/site/sphinx/agent.md @@ -6,7 +6,7 @@ 比如下载全量的arthas zip包,解压之后以 `-javaagent` 的参数指定`arthas-agent.jar`来启动: ``` -java -javaagent:/tmp/test/arthas-agent.jar -jar arthas-demo.jar +java -javaagent:/tmp/test/arthas-agent.jar -jar math-game.jar ``` 默认的配置项在解压目录里的`arthas.properties`文件里。参考:[Arthas Properties](arthas-properties.md) diff --git a/site/src/site/sphinx/arthas-properties.md b/site/src/site/sphinx/arthas-properties.md index d7af00d38..f6f49c7c1 100644 --- a/site/src/site/sphinx/arthas-properties.md +++ b/site/src/site/sphinx/arthas-properties.md @@ -10,13 +10,18 @@ Arthas Properties ## 支持的配置项 +> 注意配置必须是`驼峰`的,和spring boot的`-`风格不一样。spring boot应用才同时支持`驼峰` 和 `-`风格的配置。 ``` #arthas.config.overrideAll=true arthas.telnetPort=3658 arthas.httpPort=8563 -arthas.ip=localhost +arthas.ip=127.0.0.1 +# seconds +arthas.sessionTimeout=1800 + +#arthas.appName=demoapp #arthas.tunnelServer=ws://127.0.0.1:7777/ws #arthas.agentId=mmmmmmyiddddd ``` @@ -27,6 +32,21 @@ arthas.ip=localhost > 如果是防止一个机器上启动多个 arthas端口冲突。可以配置为随机端口,或者配置为 -1,并且通过tunnel server来使用arthas。 + +### 禁止指定命令 + +> since 3.5.2 + +比如配置: + +``` +arthas.disabledCommands=stop,dump +``` + +也可以在命令行配置: `--disabled-commands stop,dump` 。 + +> 默认情况下,arthas-spring-boot-starter会禁掉`stop`命令。 + ## 配置的优先级 配置的优先级是:命令行参数 > System Env > System Properties > arthas.properties 。 diff --git a/site/src/site/sphinx/auth.md b/site/src/site/sphinx/auth.md new file mode 100644 index 000000000..739dab790 --- /dev/null +++ b/site/src/site/sphinx/auth.md @@ -0,0 +1,72 @@ +auth +=== + +> 验证当前会话 + +### 配置用户名和密码 + +在attach时,可以在命令行指定密码。比如: + +``` +java -jar arthas-boot.jar --password ppp +``` + +* 可以通过 `--username` 选项来指定用户,默认值是`arthas`。 +* 也可以在 `arthas.properties` 里中配置 username/password。命令行的优先级大于配置文件。 +* 如果只配置`username`,没有配置`password`,则会生成随机密码,打印在`~/logs/arthas/arthas.log`中 + + ``` + Using generated security password: 0vUBJpRIppkKuZ7dYzYqOKtranj4unGh + ``` + +### 在telnet console里鉴权 + +连接到arthas后,直接执行命令会提示需要鉴权: + +```bash +[arthas@37430]$ help +Error! command not permitted, try to use 'auth' command to authenticates. +``` + +使用`auth`命令来鉴权,成功之后可以执行其它命令。 + +``` +[arthas@37430]$ auth ppp +Authentication result: true +``` + +* 可以通过 `--username` 选项来指定用户,默认值是`arthas`。 + + +### Web console密码验证 + +打开浏览器,会有弹窗提示需要输入 用户名 和 密码。 + +成功之后,则可以直接连接上 web console。 + +### HTTP API 验证 + + +#### Authorization Header方式(推荐) +Arthas 采用的是 HTTP 标准的 Basic Authorization,客户端请求时增加对应的header即可。 + +* 参考:[https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) + + +例如,用户名是:`admin`,密码是 `admin`,则组合为字符串: `admin:admin`,base64结果是: `YWRtaW46YWRtaW4=`,则HTTP 请求增加`Authorization` header: + +```bash +curl 'http://localhost:8563/api' \ + -H 'Authorization: Basic YWRtaW46YWRtaW4=' \ + --data-raw '{"action":"exec","command":"version"}' +``` + +#### URL 参数传递方式 + +为了方便各种特殊情况,支持了以 parameters 方式传递username和password。比如: + +```bash +curl 'http://localhost:8563/api?password=admin' \ + --data-raw '{"action":"exec","command":"version"}' +``` + diff --git a/site/src/site/sphinx/base64.md b/site/src/site/sphinx/base64.md new file mode 100644 index 000000000..1383f9dcd --- /dev/null +++ b/site/src/site/sphinx/base64.md @@ -0,0 +1,36 @@ +base64 +=== + + +> base64编码转换,和linux里的 base64 命令类似。 + + +### 对文件进行 base64 编码 + +```bash +[arthas@70070]$ echo 'abc' > /tmp/test.txt +[arthas@70070]$ cat /tmp/test.txt +abc + +[arthas@70070]$ base64 /tmp/test.txt +YWJjCg== +``` + +### 对文件进行 base64 编码并把结果保存到文件里 + +```bash +$ base64 --input /tmp/test.txt --output /tmp/result.txt +``` + +### 用 base64 解码文件 + +``` +$ base64 -d /tmp/result.txt +abc +``` + +### 用 base64 解码文件并保存结果到文件里 + +```bash +$ base64 -d /tmp/result.txt --output /tmp/bbb.txt +``` diff --git a/site/src/site/sphinx/classloader.md b/site/src/site/sphinx/classloader.md index 4caebbf68..4039a2b4d 100644 --- a/site/src/site/sphinx/classloader.md +++ b/site/src/site/sphinx/classloader.md @@ -64,7 +64,7 @@ Affect(row-cnt:4) cost in 3 ms. ```bash $ classloader -c 3d4eac69 -file:/private/tmp/arthas-demo.jar +file:/private/tmp/math-game.jar file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar Affect(row-cnt:9) cost in 3 ms. @@ -76,7 +76,7 @@ Affect(row-cnt:9) cost in 3 ms. ```bash $ classloader --classLoaderClass sun.misc.Launcher$AppClassLoader -file:/private/tmp/arthas-demo.jar +file:/private/tmp/math-game.jar file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar Affect(row-cnt:9) cost in 3 ms. @@ -87,7 +87,7 @@ Affect(row-cnt:9) cost in 3 ms. ```bash $ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF - jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF + jar:file:/private/tmp/math-game.jar!/META-INF/MANIFEST.MF jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF ``` @@ -104,7 +104,7 @@ $ classloader -c 1b6d3586 -r java/lang/String.class $ classloader -c 3d4eac69 --load demo.MathGame load class success. class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false diff --git a/site/src/site/sphinx/cls.md b/site/src/site/sphinx/cls.md new file mode 100644 index 000000000..136f4092b --- /dev/null +++ b/site/src/site/sphinx/cls.md @@ -0,0 +1,7 @@ +cls +=== + +清空当前屏幕区域。 + +> 非终端模式下使用cls指令,会提示"Command 'cls' is only support tty session."。 + diff --git a/site/src/site/sphinx/commands.md b/site/src/site/sphinx/commands.md index a48066d8a..132af9199 100644 --- a/site/src/site/sphinx/commands.md +++ b/site/src/site/sphinx/commands.md @@ -18,10 +18,12 @@ * [sm](sm.md) * [dump](dump.md) * [heapdump](heapdump.md) +* [vmtool](vmtool.md) * [jad](jad.md) * [classloader](classloader.md) * [mc](mc.md) +* [retransform](retransform.md) * [redefine](redefine.md) * [monitor](monitor.md) @@ -35,18 +37,20 @@ * [cat](cat.md) * [echo](echo.md) * [grep](grep.md) +* [base64](base64.md) * [tee](tee.md) * [pwd](pwd.md) +* [auth](auth.md) * [options](options.md) ### Arthas 基础命令 -* help——查看命令帮助信息 -* cls——清空当前屏幕区域 -* session——查看当前会话的信息 -* [reset](reset.md)——重置增强类,将被 Arthas 增强过的类全部还原,Arthas 服务端关闭时会重置所有增强过的类 -* version——输出当前目标 Java 进程所加载的 Arthas 版本号 -* history——打印命令历史 -* quit——退出当前 Arthas 客户端,其他 Arthas 客户端不受影响 -* stop——关闭 Arthas 服务端,所有 Arthas 客户端全部退出 -* [keymap](keymap.md)——Arthas快捷键列表及自定义快捷键 \ No newline at end of file +* [help](help.md) +* [cls](cls.md) +* [session](session.md) +* [reset](reset.md) +* [version](version.md) +* [history](history.md) +* [quit](quit.md) +* [stop](stop.md) +* [keymap](keymap.md) \ No newline at end of file diff --git a/site/src/site/sphinx/conf.py b/site/src/site/sphinx/conf.py index 5f09f0f14..52f586940 100644 --- a/site/src/site/sphinx/conf.py +++ b/site/src/site/sphinx/conf.py @@ -67,13 +67,13 @@ github_doc_root = 'https://github.com/alibaba/arthas/tree/master/site/src/site/s # The full version, including alpha/beta/rc tagss # release = # read version from pom.xml -rootDir = os.path.dirname(os.path.abspath(__file__)) + '/../../..' +rootDir = os.path.dirname(os.path.abspath(__file__)) + '/../../../..' pomXml = ET.parse(rootDir + '/pom.xml') for projectChildrenElem in list(pomXml.getroot()): - if projectChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}parent': + if projectChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}properties': for parentChildrenElem in list(projectChildrenElem): - if parentChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}version': + if parentChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}revision': version = parentChildrenElem.text # if version is SNAPSHOT, read final release from maven center diff --git a/site/src/site/sphinx/contact-us.md b/site/src/site/sphinx/contact-us.md index 6032587af..57048d0ce 100644 --- a/site/src/site/sphinx/contact-us.md +++ b/site/src/site/sphinx/contact-us.md @@ -2,11 +2,22 @@ === + +## 招聘 + +* [期待你的加入](https://mp.weixin.qq.com/s/XQv8GnqGT3pzceVwzeiy-A) ### Issues + 使用疑问,意见可以直接在Issues里提出: [https://github.com/alibaba/arthas/issues](https://github.com/alibaba/arthas/issues) +### 微信公众号 + +欢迎关注公众号,获取Arthas项目的信息、源码分析、案例实践。 + +![](_static/qrcode_gongzhonghao.jpg) + ### 钉钉群 * Arthas开源交流钉钉群: 21965291 ,搜索群号即可加入。 @@ -21,9 +32,13 @@ ### QQ群 -Arthas开源交流QQ群:916328269 +Arthas开源交流QQ群: 916328269 ![](_static/qqgroup_qr.jpg) +Arthas开源交流QQ群2: 854625984 + +![](_static/qqgroup2_qr.jpg) + diff --git a/site/src/site/sphinx/docker.md b/site/src/site/sphinx/docker.md index 935c230c1..e70111e40 100644 --- a/site/src/site/sphinx/docker.md +++ b/site/src/site/sphinx/docker.md @@ -56,22 +56,22 @@ RUN export JAVA_HOME ## 通过Docker快速入门 -1. 删除本地已有的`arthas-demo` docker container(非必要) +1. 删除本地已有的`math-game` docker container(非必要) ```sh - $ docker stop arthas-demo || true && docker rm arthas-demo || true + $ docker stop math-game || true && docker rm math-game || true ``` -1. 启动`arthas-demo` +1. 启动`math-game` ```sh - $ docker run --name arthas-demo -it hengyunabc/arthas:latest /bin/sh -c "java -jar /opt/arthas/arthas-demo.jar" + $ docker run --name math-game -it hengyunabc/arthas:latest /bin/sh -c "java -jar /opt/arthas/math-game.jar" ``` 1. 启动`arthas-boot`来进行诊断 ```sh - $ docker exec -it arthas-demo /bin/sh -c "java -jar /opt/arthas/arthas-boot.jar" + $ docker exec -it math-game /bin/sh -c "java -jar /opt/arthas/arthas-boot.jar" * [1]: 9 jar [INFO] arthas home: /opt/arthas diff --git a/site/src/site/sphinx/en/advanced-use.md b/site/src/site/sphinx/en/advanced-use.md index 5b8194e74..dba45d449 100644 --- a/site/src/site/sphinx/en/advanced-use.md +++ b/site/src/site/sphinx/en/advanced-use.md @@ -8,6 +8,7 @@ Advanced Usage * [cat](cat.md) - Concatenate and print files * [echo](echo.md) - write arguments to the standard output * [grep](grep.md) - Pattern searcher +* [base64](base64.md) - Encode and decode using Base64 representation. * [tee](tee.md) - Copies standard input to standard output, making a copy in zero or more files. * [pwd](pwd.md) - Return working directory name * session - display current session information @@ -32,13 +33,14 @@ Advanced Usage * [ognl](ognl.md) - execute ognl expression * [mbean](mbean.md) - show Mbean information * [heapdump](heapdump.md) - dump java heap in hprof binary format, like `jmap` - +* [vmtool](vmtool.md) - jvm tool, getInstances in jvm, forceGc ## class/classloader * [sc](sc.md) - check the info for the classes loaded by JVM * [sm](sm.md) - check methods info for the loaded classes * [jad](jad.md) - decompile the specified loaded classes * [mc](mc.md) - Memory compiler, compiles `.java` files into `.class` files in memory +* [retransform](retransform.md) - load external `*.class` files and retransform it into JVM * [redefine](redefine.md) - load external `*.class` files and re-define it into JVM * [dump](dump.md) - dump the loaded classes in byte code to the specified location * [classloader](classloader.md) - check the inheritance structure, urls, class loading info for the specified class; using classloader to get the url of the resource e.g. `java/lang/String.class` @@ -53,6 +55,10 @@ Advanced Usage * [stack](stack.md) - display the stack trace for the specified class and method * [tt](tt.md) - time tunnel, record the arguments and returned value for the methods and replay +## authentication + +* [auth](auth.md) - authentication + ## options * [options](options.md) - check/set Arthas global options @@ -101,18 +107,18 @@ Arthas supports living inside a browser. The communication between arthas and br Normally, `as.sh`/`arthas-boot.jar` needs to a pid, bacause the pid will change. -For example, with `arthas-demo.jar` already started, use the `jps` command to see. +For example, with `math-game.jar` already started, use the `jps` command to see. ```bash $ jps -58883 arthas-demo.jar +58883 math-game.jar 58884 Jps ``` The `select` option allows you to specify a process name, which is very convenient. ```bash -$ ./as.sh --select arthas-demo +$ ./as.sh --select math-game Arthas script version: 3.3.6 [INFO] JAVA_HOME: /tmp/java/8.0.222-zulu Arthas home: /Users/admin/.arthas/lib/3.3.6/arthas diff --git a/site/src/site/sphinx/en/agent.md b/site/src/site/sphinx/en/agent.md index 005508fbf..00f62ef9d 100644 --- a/site/src/site/sphinx/en/agent.md +++ b/site/src/site/sphinx/en/agent.md @@ -6,7 +6,7 @@ Usually Arthas dynamic attach the applications on the fly, but from version `3.2 For example, download the full arthas zip package, decompress it and start it by specifying `arthas-agent.jar` with the parameter `-javaagent`. ```` -java -javaagent:/tmp/test/arthas-agent.jar -jar arthas-demo.jar +java -javaagent:/tmp/test/arthas-agent.jar -jar math-game.jar ```` The default configuration is in the `arthas.properties` file in the decompression directory. Reference: [Arthas Properties](arthas-properties.md) diff --git a/site/src/site/sphinx/en/arthas-properties.md b/site/src/site/sphinx/en/arthas-properties.md index 312764242..9f3a5a7f7 100644 --- a/site/src/site/sphinx/en/arthas-properties.md +++ b/site/src/site/sphinx/en/arthas-properties.md @@ -8,12 +8,18 @@ The `arthas.properties` file is in the arthas directory. ## Supported configuration items +> Note that the configuration must be `camel case`, which is different from the `-` style of spring boot. Only the spring boot application supports both `camel case` and `-` style configuration. + ``` #arthas.config.overrideAll=true arthas.telnetPort=3658 arthas.httpPort=8563 -arthas.ip=localhost +arthas.ip=127.0.0.1 + +# seconds +arthas.sessionTimeout=1800 +#arthas.appName=demoapp #arthas.tunnelServer=ws://127.0.0.1:7777/ws #arthas.agentId=mmmmmmyiddddd ``` @@ -24,6 +30,22 @@ arthas.ip=localhost > If you want to prevent multiple arthas port conflicts on a machine. It can be configured as a random port, or configured as -1, and use arthas through the tunnel server. + +### disable specify commands + +> since 3.5.2 + +Such as configuration: + +``` +arthas.disabledCommands=stop,dump +``` + +It can also be configured on the command line: `--disabled-commands stop,dump`. + +> By default, arthas-spring-boot-starter will disable the `stop` command. + + ## Configured order The order of configuration is: command line parameters > System Env > System Properties > arthas.properties. diff --git a/site/src/site/sphinx/en/auth.md b/site/src/site/sphinx/en/auth.md new file mode 100644 index 000000000..937e3aa9e --- /dev/null +++ b/site/src/site/sphinx/en/auth.md @@ -0,0 +1,69 @@ +auth +=== + +> Authenticates the current session + +### Configure username and password + +When attaching, you can specify a password on the command line. such as: + +``` +java -jar arthas-boot.jar --password ppp +``` + +* The user can be specified by the `--username` option, the default value is `arthas`. +* You can also configure username/password in `arthas.properties`. The priority of the command line is higher than that of the configuration file. +* If only `username` is configured and no `password` is configured, a random password will be generated and printed in `~/logs/arthas/arthas.log` + + ``` + Using generated security password: 0vUBJpRIppkKuZ7dYzYqOKtranj4unGh + ``` + +### Authenticate in the telnet console + +After connecting to arthas, directly executing the command will prompt for authentication: + +```bash +[arthas@37430]$ help +Error! command not permitted, try to use 'auth' command to authenticates. +``` + +Use the `auth` command to authenticate, and you can execute other commands after success. + +``` +[arthas@37430]$ auth ppp +Authentication result: true +``` + +* The user can be specified by the `--username` option, the default value is `arthas`. + +### Web console Authentication + +Open the browser, there will be a pop-up window prompting you to enter your username and password. + +After success, you can directly connect to the web console. + +### HTTP API Authentication + +#### HTTP Authorization Header(recommended) + +Arthas uses the HTTP standard Basic Authorization. + +* Reference: [https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication) + +For example, if the user name is: `admin` and the password is `admin`, the combination is a string: `admin:admin`, the base64 result is: `YWRtaW46YWRtaW4=`, then the HTTP request adds the `Authorization` header: + +```bash +curl 'http://localhost:8563/api' \ + -H 'Authorization: Basic YWRtaW46YWRtaW4=' \ + --data-raw '{"action":"exec","command":"version"}' +``` + +#### URL parameters + +It supports passing username and password in parameters. such as: + +```bash +curl 'http://localhost:8563/api?password=admin' \ + --data-raw '{"action":"exec","command":"version"}' +``` \ No newline at end of file diff --git a/site/src/site/sphinx/en/base64.md b/site/src/site/sphinx/en/base64.md new file mode 100644 index 000000000..cd85bdb50 --- /dev/null +++ b/site/src/site/sphinx/en/base64.md @@ -0,0 +1,36 @@ +base64 +=== + + +> Encode and decode using Base64 representation. + + +### Encode to base64 + +```bash +[arthas@70070]$ echo 'abc' > /tmp/test.txt +[arthas@70070]$ cat /tmp/test.txt +abc + +[arthas@70070]$ base64 /tmp/test.txt +YWJjCg== +``` + +### Encode to base64 and save output to file + +```bash +$ base64 --input /tmp/test.txt --output /tmp/result.txt +``` + +### Decode from base64 + +``` +$ base64 -d /tmp/result.txt +abc +``` + +### Decode from base64 and save output to file + +```bash +$ base64 -d /tmp/result.txt --output /tmp/bbb.txt +``` diff --git a/site/src/site/sphinx/en/classloader.md b/site/src/site/sphinx/en/classloader.md index 7de391342..c835230ab 100644 --- a/site/src/site/sphinx/en/classloader.md +++ b/site/src/site/sphinx/en/classloader.md @@ -61,7 +61,7 @@ Affect(row-cnt:4) cost in 3 ms. ```bash $ classloader -c 3d4eac69 -file:/private/tmp/arthas-demo.jar +file:/private/tmp/math-game.jar file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar Affect(row-cnt:9) cost in 3 ms. @@ -73,7 +73,7 @@ For ClassLoader with only unique instance, it can be specified by class name, wh ```bash $ classloader --classLoaderClass sun.misc.Launcher$AppClassLoader -file:/private/tmp/arthas-demo.jar +file:/private/tmp/math-game.jar file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar Affect(row-cnt:9) cost in 3 ms. @@ -84,7 +84,7 @@ Affect(row-cnt:9) cost in 3 ms. ```bash $ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF - jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF + jar:file:/private/tmp/math-game.jar!/META-INF/MANIFEST.MF jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF ``` @@ -101,7 +101,7 @@ $ classloader -c 1b6d3586 -r java/lang/String.class $ classloader -c 3d4eac69 --load demo.MathGame load class success. class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false diff --git a/site/src/site/sphinx/en/cls.md b/site/src/site/sphinx/en/cls.md new file mode 100644 index 000000000..575d0fb12 --- /dev/null +++ b/site/src/site/sphinx/en/cls.md @@ -0,0 +1,7 @@ +cls +=== + +clear current console. + +> if not in tty mode,it will warn "Command 'cls' is only support tty session.". + diff --git a/site/src/site/sphinx/en/commands.md b/site/src/site/sphinx/en/commands.md index f60729ee3..a4a3eeae3 100644 --- a/site/src/site/sphinx/en/commands.md +++ b/site/src/site/sphinx/en/commands.md @@ -18,10 +18,12 @@ All Commands * [sm](sm.md) * [dump](dump.md) * [heapdump](heapdump.md) +* [vmtool](vmtool.md) * [jad](jad.md) * [classloader](classloader.md) * [mc](mc.md) +* [retransform](retransform.md) * [redefine](redefine.md) * [monitor](monitor.md) @@ -35,8 +37,10 @@ All Commands * [cat](cat.md) * [echo](echo.md) * [grep](grep.md) +* [base64](base64.md) * [tee](tee.md) * [pwd](pwd.md) +* [auth](auth.md) * [options](options.md) diff --git a/site/src/site/sphinx/en/conf.py b/site/src/site/sphinx/en/conf.py index 148cf3fa4..67e9b6aee 100644 --- a/site/src/site/sphinx/en/conf.py +++ b/site/src/site/sphinx/en/conf.py @@ -67,13 +67,13 @@ github_doc_root = 'https://github.com/alibaba/arthas/tree/master/site/src/site/s # The full version, including alpha/beta/rc tagss # release = # read version from pom.xml -rootDir = os.path.dirname(os.path.abspath(__file__)) + '/../../../..' +rootDir = os.path.dirname(os.path.abspath(__file__)) + '/../../../../..' pomXml = ET.parse(rootDir + '/pom.xml') for projectChildrenElem in list(pomXml.getroot()): - if projectChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}parent': + if projectChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}properties': for parentChildrenElem in list(projectChildrenElem): - if parentChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}version': + if parentChildrenElem.tag == '{http://maven.apache.org/POM/4.0.0}revision': version = parentChildrenElem.text # if version is SNAPSHOT, read final release from maven center diff --git a/site/src/site/sphinx/en/contact-us.md b/site/src/site/sphinx/en/contact-us.md index 8dc894799..3720bbcb0 100644 --- a/site/src/site/sphinx/en/contact-us.md +++ b/site/src/site/sphinx/en/contact-us.md @@ -38,4 +38,7 @@ Arthas open source discussion QQ group:916328269 ![](_static/qqgroup_qr.jpg) +Arthas open source discussion QQ group2:854625984 + +![](_static/qqgroup2_qr.jpg) diff --git a/site/src/site/sphinx/en/docker.md b/site/src/site/sphinx/en/docker.md index 84acac19a..f42faecba 100644 --- a/site/src/site/sphinx/en/docker.md +++ b/site/src/site/sphinx/en/docker.md @@ -58,22 +58,22 @@ RUN export JAVA_HOME ## Quick start with Docker -1. Delete the existing `arthas-demo` docker container (not necessary) +1. Delete the existing `math-game` docker container (not necessary) ```sh - $ docker stop arthas-demo || true && docker rm arthas-demo || true + $ docker stop math-game || true && docker rm math-game || true ``` -1. Start `arthas-demo` +1. Start `math-game` ```sh - $ docker run --name arthas-demo -it hengyunabc/arthas:latest /bin/sh -c "java -jar /opt/arthas/arthas-demo.jar" + $ docker run --name math-game -it hengyunabc/arthas:latest /bin/sh -c "java -jar /opt/arthas/math-game.jar" ``` 1. Start `arthas-boot` for diagnosis ```sh - $ docker exec -it arthas-demo /bin/sh -c "java -jar /opt/arthas/arthas-boot.jar" + $ docker exec -it math-game /bin/sh -c "java -jar /opt/arthas/arthas-boot.jar" * [1]: 9 jar [INFO] arthas home: /opt/arthas diff --git a/site/src/site/sphinx/en/faq.md b/site/src/site/sphinx/en/faq.md new file mode 100644 index 000000000..bf74fb0ea --- /dev/null +++ b/site/src/site/sphinx/en/faq.md @@ -0,0 +1,94 @@ +## FAQ + + +> For questions that are not in this list, please search in issues. [https://github.com/alibaba/arthas/issues](https://github.com/alibaba/arthas/issues) + + +##### Where is the log file? + +Log file path: `~/logs/arthas/arthas.log` +##### How much impact does Arthas attach have on the performance of the original process? + +[https://github.com/alibaba/arthas/issues/44](https://github.com/alibaba/arthas/issues/44) + + +##### target process not responding or HotSpot VM not loaded + +com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded + +1. Check whether the current user and the target java process are consistent. If they are inconsistent, switch to the same user. JVM can only attach java processes under the same user. +2. Try to use `jstack -l $pid`. If the process does not respond, it means that the process may freeze and fail to respond to the JVM attach signal. So Arthas based on the attach mechanism cannot work. Try to use `jmap` heapdump to analyze. +3. Try to attach math-game in [quick-start](quick-start.md). +4. For more information: [https://github.com/alibaba/arthas/issues/347](https://github.com/alibaba/arthas/issues/347) + + +##### Can commands such as trace/watch enhance the classes in jdk? + +By default, classes beginning with `java.` are filtered out, but they can be turned on: + +```bash +options unsafe true +``` + +See more at [options](options.md) + + +##### How to view the result in `json` format + +```bash +options json-format true +``` + +See more at [options](options.md) + + +##### Can arthas trace native methods + +No. + +##### Can arthas view the value of a variable in memory? + +1. You can use [`vmtool`](vmtool.md) command. +2. You can use some tricks to intercept the object with the [`tt`](tt.md) command, or fetch it from a static method. + + +##### How to filter method with the same name? + +You can used all variables in [fundamental fields in expressions](advice-class.md) for the condition express to filter method with the same name, you can use the number of parameters `params.length ==1`,parameter type `params[0] instanceof java.lang.Integer`,return value type `returnObj instanceof java.util.List` and so on in one or more combinations as condition express. + +You can use `-v` to view the condition express result [https://github.com/alibaba/arthas/issues/1348](https://github.com/alibaba/arthas/issues/1348) + +example [math-game](quick-start.md) + +```bash +watch demo.MathGame primeFactors '{params,returnObj,throwExp}' 'params.length >0 && returnObj instanceof java.util.List' -v +``` + +##### How to watch or trace constructor? + +```bash +watch demo.MathGame '{params,returnObj,throwExp}' -v +``` + + +##### java.lang.ClassFormatError: null, skywalking arthas compatible use + +When error log appear `java.lang.ClassFormatError: null`, it is usually modified by other bytecode tools that are not compatible with arthas modified bytecode. + +For example: use skywalking V8.1.0 below [cannot trace, watch classes enhanced by skywalking agent](https://github.com/alibaba/arthas/issues/1141), V8.1.0 or above is compatible, refer to skywalking configuration for more details. [skywalking compatible with other javaagent bytecode processing](https://github.com/apache/skywalking/blob/v8.1.0/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md). + + +##### Can I use arthas offline? + +Yes. Just download the full size package and unzip it, refer to: [Download](download.md). + +##### Attach the process with pid 1 in docker/k8s failed + +Reference: [https://github.com/alibaba/arthas/issues/362#issuecomment-448185416](https://github.com/alibaba/arthas/issues/362#issuecomment-448185416) + + +##### Why is the new version of Arthas downloaded, but the old version is connected? + +For example, the started version of `as.sh/arthas-boot.jar` is 3.5.*, but after connecting, the printed arthas version is 3.4.*. + +It may be that the target process has been diagnosed with the old version of arthas before. You can execute `stop` to stop the old version of arthas, and then reuse the new version to attach. \ No newline at end of file diff --git a/site/src/site/sphinx/en/help.md b/site/src/site/sphinx/en/help.md new file mode 100644 index 000000000..bc0b48d6e --- /dev/null +++ b/site/src/site/sphinx/en/help.md @@ -0,0 +1,87 @@ +help +=== + +show help message, the command can show all the commands that current Arthas server supports,or you can use the command to show the detail usage of another command. + +> [help command] equals [command -help],both is to show the detail usage of one command. + +### Options + +| Name | Specification | +| ------: | :-------------------------------------------------------- | +| | show all the commands that current Arthas server supports | +| [name:] | show the detail usage of one command | + +### Usage + +```bash +$ help + NAME DESCRIPTION + help Display Arthas Help + auth Authenticates the current session + keymap Display all the available keymap for the specified connection. + sc Search all the classes loaded by JVM + sm Search the method of classes loaded by JVM + classloader Show classloader info + jad Decompile class + getstatic Show the static field of a class + monitor Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc. + stack Display the stack trace for the specified class and method + thread Display thread info, thread stack + trace Trace the execution time of specified method invocation. + watch Display the input/output parameter, return object, and thrown exception of specified method invocation + tt Time Tunnel + jvm Display the target JVM information + perfcounter Display the perf counter information. + ognl Execute ognl expression. + mc Memory compiler, compiles java files into bytecode and class files in memory. + redefine Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...) + retransform Retransform classes. @see Instrumentation#retransformClasses(Class...) + dashboard Overview of target jvm's thread, memory, gc, vm, tomcat info. + dump Dump class byte array from JVM + heapdump Heap dump + options View and change various Arthas options + cls Clear the screen + reset Reset all the enhanced classes + version Display Arthas version + session Display current session information + sysprop Display, and change the system properties. + sysenv Display the system env. + vmoption Display, and update the vm diagnostic options. + logger Print logger info, and update the logger level + history Display command history + cat Concatenate and print files + base64 Encode and decode using Base64 representation + echo write arguments to the standard output + pwd Return working directory name + mbean Display the mbean information + grep grep command for pipes. + tee tee command for pipes. + profiler Async Profiler. https://github.com/jvm-profiling-tools/async-profiler + stop Stop/Shutdown Arthas server and exit the console. + + +``` + +```bash + $ help dashboard + USAGE: + dashboard [-h] [-i ] [-n ] + + SUMMARY: + Overview of target jvm's thread, memory, gc, vm, tomcat info. + + EXAMPLES: + dashboard + dashboard -n 10 + dashboard -i 2000 + + WIKI: + https://arthas.aliyun.com/doc/dashboard + + OPTIONS: + -h, --help this help + -i, --interval The interval (in ms) between two executions, default is 5000 ms. + -n, --number-of-execution The number of times this command will be executed. +``` + diff --git a/site/src/site/sphinx/en/history.md b/site/src/site/sphinx/en/history.md new file mode 100644 index 000000000..18a48eabe --- /dev/null +++ b/site/src/site/sphinx/en/history.md @@ -0,0 +1,31 @@ +history +=== + +view command history. + +> history of commands will persisted in a file named history, so the history command can show all the history commands of current Arthas server ,but not only history in current session. + +### Options + +| Name | Specification | +| ---: | :----------------------------- | +| [c:] | clear all the history commands | +| [n:] | view the nearest 5 commands | + +### 使用参考 + +```bash +#view the nearest 3 commands +$ history 3 + 269 thread + 270 cls + 271 history 3 +``` + +```bash + #clear all the history commands + $ history -c + $ history 3 + 1 history 3 +``` + diff --git a/site/src/site/sphinx/en/http-api.md b/site/src/site/sphinx/en/http-api.md index 4c95844b7..af386f35c 100644 --- a/site/src/site/sphinx/en/http-api.md +++ b/site/src/site/sphinx/en/http-api.md @@ -492,6 +492,10 @@ curl -Ss -XPOST http://localhost:8563/api -d ''' } ``` +### Authentication + +* Reference: [auth](auth.md) + ### Web UI ![](../_static/arthas-web-ui.png "arthas web ui") diff --git a/site/src/site/sphinx/en/idea-plugin.md b/site/src/site/sphinx/en/idea-plugin.md index 25f9556b6..f0019959e 100644 --- a/site/src/site/sphinx/en/idea-plugin.md +++ b/site/src/site/sphinx/en/idea-plugin.md @@ -5,7 +5,7 @@ IDEA Plugin * Jetbrains Plugin: [https://plugins.jetbrains.com/plugin/13581-arthas-idea](https://plugins.jetbrains.com/plugin/13581-arthas-idea) -* Plugin Doc:[https://www.yuque.com/docs/share/fa77c7b4-c016-4de6-9fa3-58ef25a97948?#](https://www.yuque.com/docs/share/fa77c7b4-c016-4de6-9fa3-58ef25a97948?#) +* Plugin Doc:[https://www.yuque.com/arthas-idea-plugin](https://www.yuque.com/arthas-idea-plugin) * Plugin Github: [https://github.com/WangJi92/arthas-idea-plugin](https://github.com/WangJi92/arthas-idea-plugin) diff --git a/site/src/site/sphinx/en/index.md b/site/src/site/sphinx/en/index.md index f00865734..0d2cf3181 100644 --- a/site/src/site/sphinx/en/index.md +++ b/site/src/site/sphinx/en/index.md @@ -30,6 +30,7 @@ Arthas is built to solve these issues. A developer can troubleshoot production i * Supports command line interactive mode, with auto-complete feature enabled. * Supports telnet and WebSocket, which enables both local and remote diagnostics with command line and browsers. * Supports profiler/Flame Graph +* Support get objects in the heap that are instances of the specified class. * Supports JDK 6+ * Supports Linux/Mac/Windows @@ -47,13 +48,14 @@ Contents * [Advanced usage](advanced-use.md) * [Commands](commands.md) * [WebConsole](web-console.md) +* [Arthas Tunnel](tunnel.md) * [Http API](http-api.md) * [Docker](docker.md) * [Arthas Spring Boot Starter](spring-boot-starter.md) * [IDEA Plugin](idea-plugin.md) * [User cases](https://github.com/alibaba/arthas/issues?q=label%3Auser-case) -* [Questions and answers](https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered) -* [Fork me at GitHub](https://github.com/alibaba/arthas) +* [FAQ](faq.md) +* [Star me at GitHub](https://github.com/alibaba/arthas) * [Compile and debug/CONTRIBUTING](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md#) * [Release Notes](https://github.com/alibaba/arthas/releases) * [Contact us](contact-us.md) diff --git a/site/src/site/sphinx/en/jad.md b/site/src/site/sphinx/en/jad.md index 4c7347bec..b364c3a5b 100644 --- a/site/src/site/sphinx/en/jad.md +++ b/site/src/site/sphinx/en/jad.md @@ -31,35 +31,39 @@ ClassLoader: Location: -/* -* Decompiled with CFR 0_132. -*/ -package java.lang; + /* + * Decompiled with CFR. + */ + package java.lang; -import java.io.ObjectStreamField; + import java.io.ObjectStreamField; + import java.io.Serializable; ... -public final class String -implements Serializable, -Comparable, -CharSequence { - private final char[] value; - private int hash; - private static final long serialVersionUID = -6849794470754667710L; - private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; - public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); - - public String(byte[] arrby, int n, int n2) { - String.checkBounds(arrby, n, n2); - this.value = StringCoding.decode(arrby, n, n2); - } + public final class String + implements Serializable, + Comparable, + CharSequence { + private final char[] value; + private int hash; + private static final long serialVersionUID = -6849794470754667710L; + private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; + public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); +... + public String(byte[] byArray, int n, int n2, Charset charset) { +/*460*/ if (charset == null) { + throw new NullPointerException("charset"); + } +/*462*/ String.checkBounds(byArray, n, n2); +/*463*/ this.value = StringCoding.decode(charset, byArray, n, n2); + } ... ``` #### Print source only -By default, the decompile result will have the `ClassLoader` information. With the `--source-only` option, you can print only the source code. Conveniently used with the [mc](mc.md)/[redefine](redefine.md) commands. +By default, the decompile result will have the `ClassLoader` information. With the `--source-only` option, you can print only the source code. Conveniently used with the [mc](mc.md)/[retransform](retransform.md) commands. -``` +```java $ jad --source-only demo.MathGame /* * Decompiled with CFR 0_132. @@ -85,21 +89,42 @@ public class MathGame { $ jad demo.MathGame main ClassLoader: -+-sun.misc.Launcher$AppClassLoader@3d4eac69 -+-sun.misc.Launcher$ExtClassLoader@66350f69 ++-sun.misc.Launcher$AppClassLoader@232204a1 + +-sun.misc.Launcher$ExtClassLoader@7f31245a + +Location: +/private/tmp/math-game.jar + + public static void main(String[] args) throws InterruptedException { + MathGame game = new MathGame(); + while (true) { +/*16*/ game.run(); +/*17*/ TimeUnit.SECONDS.sleep(1L); + } + } +``` + +#### Do not print line numbers + +* `--lineNumber`: Output source code contins line numbers, default value true + +```java +$ jad demo.MathGame main --lineNumber false + +ClassLoader: ++-sun.misc.Launcher$AppClassLoader@232204a1 + +-sun.misc.Launcher$ExtClassLoader@7f31245a Location: -/private/tmp/arthas-demo.jar +/private/tmp/math-game.jar public static void main(String[] args) throws InterruptedException { MathGame game = new MathGame(); - do { + while (true) { game.run(); TimeUnit.SECONDS.sleep(1L); - } while (true); + } } - -Affect(row-cnt:1) cost in 228 ms. ``` #### Decompile with specified classLoader diff --git a/site/src/site/sphinx/en/mc.md b/site/src/site/sphinx/en/mc.md index 455b655f3..933e972b8 100644 --- a/site/src/site/sphinx/en/mc.md +++ b/site/src/site/sphinx/en/mc.md @@ -1,7 +1,7 @@ mc === -[`mc-redefine` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-mc-redefine) +[`mc-retransform` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-mc-retransform) > Memory compiler, compiles `.java` files into `.class` files in memory. @@ -30,6 +30,6 @@ The output directory can be specified with the `-d` option: mc -d /tmp/output /tmp/ClassA.java /tmp/ClassB.java ``` -After compiling the `.class` file, you can use the [redefine](redefine.md) command to re-define the loaded classes in JVM. +After compiling the `.class` file, you can use the [retransform](retransform.md) command to re-define the loaded classes in JVM. -> Note that the mc command may fail. If the compilation fails, the `.class` file can be compiled locally and uploaded to the server. Refer to the [redefine](redefine.md) command description for details. \ No newline at end of file +> Note that the mc command may fail. If the compilation fails, the `.class` file can be compiled locally and uploaded to the server. Refer to the [retransform](retransform.md) command description for details. \ No newline at end of file diff --git a/site/src/site/sphinx/en/options.md b/site/src/site/sphinx/en/options.md index 3a5938e44..21a8a7108 100644 --- a/site/src/site/sphinx/en/options.md +++ b/site/src/site/sphinx/en/options.md @@ -83,3 +83,20 @@ $ options save-result true ---------------------------------------- save-result false true ``` + +### Set `unsafe` to true to enhance the classes under the `java.*` package + +By default, `watch`/`trace`/`tt`/`trace`/`monitor` command do not support classes under `java.*` package. You can set `unsafe` to true to enhance the classes under the `java.*` package. + +```bash +$ options unsafe true + NAME BEFORE-VALUE AFTER-VALUE +----------------------------------- + unsafe false true +``` + +```bash +$ watch java.lang.invoke.Invokers callSiteForm +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 61 ms, listenerId: 1 +``` \ No newline at end of file diff --git a/site/src/site/sphinx/en/profiler.md b/site/src/site/sphinx/en/profiler.md index cb76f965d..9ab5a9af7 100644 --- a/site/src/site/sphinx/en/profiler.md +++ b/site/src/site/sphinx/en/profiler.md @@ -227,3 +227,8 @@ The generated results can be viewed with tools that support the jfr format. such * JDK Mission Control: https://github.com/openjdk/jmc * JProfiler: https://github.com/alibaba/arthas/issues/1416 + + +### The 'unknown' in profiler result + +* https://github.com/jvm-profiling-tools/async-profiler/discussions/409 \ No newline at end of file diff --git a/site/src/site/sphinx/en/quick-start.md b/site/src/site/sphinx/en/quick-start.md index af0dee903..cab86a0b8 100644 --- a/site/src/site/sphinx/en/quick-start.md +++ b/site/src/site/sphinx/en/quick-start.md @@ -1,16 +1,16 @@ Quick Start =========== -## 1. Start Demo Application +## 1. Start math-game ```bash -curl -O https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar +curl -O https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar ``` -`arthas-demo` is a simple program that generates a random number every second, then it finds all prime factors of that number. +`math-game` is a simple program that generates a random number every second, then it finds all prime factors of that number. -The source code of `arthas-demo`: [View](https://github.com/alibaba/arthas/blob/master/demo/src/main/java/demo/MathGame.java) +The source code of `math-game`: [View](https://github.com/alibaba/arthas/blob/master/math-game/src/main/java/demo/MathGame.java) ## 2. Start Arthas @@ -32,10 +32,10 @@ Select the target Java process to attach: ```bash $ $ java -jar arthas-boot.jar * [1]: 35542 - [2]: 71560 arthas-demo.jar + [2]: 71560 math-game.jar ``` -The 'Demo' process is the second as shown above, press '2' then 'Enter'. Arthas will attach to the target process, and start to output: +The `math-game` process is the second as shown above, press '2' then 'Enter'. Arthas will attach to the target process, and start to output: ```bash [INFO] Try to attach process 71560 @@ -94,7 +94,7 @@ java.home /Library/Java/JavaVir e/jre ``` -## 4. Get the Main Class of the `arthas-demo` process with the thread command +## 4. Get the Main Class of the `math-game` process with the thread command `thread 1` will print the stack of the thread with ID 1, which usually the main function thread. @@ -113,7 +113,7 @@ ClassLoader: +-sun.misc.Launcher$ExtClassLoader@66350f69 Location: -/tmp/arthas-demo.jar +/tmp/math-game.jar /* * Decompiled with CFR 0_132. diff --git a/site/src/site/sphinx/en/quit.md b/site/src/site/sphinx/en/quit.md new file mode 100644 index 000000000..2deaec083 --- /dev/null +++ b/site/src/site/sphinx/en/quit.md @@ -0,0 +1,7 @@ +quit +=== + +exit the current Arthas client without affecting other clients. equals **exit**、**logout**、**q** command. + +> just exit Arthas client,it means Arthas server is not closed,so the changes you do will not be reseted. + diff --git a/site/src/site/sphinx/en/redefine.md b/site/src/site/sphinx/en/redefine.md index e1a36d48a..8573a50bf 100644 --- a/site/src/site/sphinx/en/redefine.md +++ b/site/src/site/sphinx/en/redefine.md @@ -1,6 +1,8 @@ redefine ======== +> Recommend to use the [retransform](retransform.md) command. + [`mc-redefine` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-mc-redefine) > Load the external `*.class` files to re-define the loaded classes in JVM. @@ -9,6 +11,8 @@ Reference: [Instrumentation#redefineClasses](https://docs.oracle.com/javase/8/do ### Frequently asked questions +> Recommend to use the [retransform](retransform.md) command. + * The class of `redefine` cannot modify, add or delete the field and method of the class, including method parameters, method names and return values. * If `mc` fails, you can compile the class file in the local development environment, upload it to the target system, and use `redefine` to hot load the class. @@ -29,7 +33,6 @@ Reference: [Instrumentation#redefineClasses](https://docs.oracle.com/javase/8/do |---:|:---| |`[c:]`|hashcode of the class loader| |`[classLoaderClass:]`| The class name of the ClassLoader that executes the expression. | -|`[p:]`|absolute path of the external `*.class`, multiple paths are separated with 'space'| ### Usage diff --git a/site/src/site/sphinx/en/retransform.md b/site/src/site/sphinx/en/retransform.md new file mode 100644 index 000000000..7af430b50 --- /dev/null +++ b/site/src/site/sphinx/en/retransform.md @@ -0,0 +1,140 @@ +retransform +======== + +[`mc-retransform` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-mc-retransform) + +> Load the external `*.class` files to retransform the loaded classes in JVM. + +Reference: [Instrumentation#retransformClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses-java.lang.Class...-) + +### Usage + +```bash + retransform /tmp/Test.class + retransform -l + retransform -d 1 # delete retransform entry + retransform --deleteAll # delete all retransform entries + retransform --classPattern demo.* # triger retransform classes + retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class + retransform --classLoaderClass 'sun.misc.Launcher$AppClassLoader' /tmp/Test.class +``` + +### retransform the specified .class file + +```bash +$ retransform /tmp/MathGame.class +retransform success, size: 1, classes: +demo.MathGame +``` + +Load the specified .class file, then parse out the class name, and then retransform the corresponding class loaded in the jvm. Every time a `.class` file is loaded, a retransform entry is recorded. + +> If retransform is executed multiple times to load the same class file, there will be multiple retransform entries. + +### View retransform entry + +```bash +$ retransform -l +Id ClassName TransformCount LoaderHash LoaderClassName +1 demo.MathGame 1 null null +``` + +* TransformCount counts the times of attempts to return the .class file corresponding to the entry in the ClassFileTransformer#transform method, but it does not mean that the transform must be successful. +### Delete the specified retransform entry + +Need to specify id: + +```bash +retransform -d 1 +``` + +### Delete all retransform entries + +```bash +retransform --deleteAll +``` + +### Explicitly trigger retransform + +```bash +$ retransform --classPattern demo.MathGame +retransform success, size: 1, classes: +demo.MathGame +``` + +> Note: For the same class, when there are multiple retransform entries, if retransform is explicitly triggered, the entry added last will take effect (the one with the largest id). + +### Eliminate the influence of retransform + +If you want to eliminate the impact after performing retransform on a class, you need to: + +* Delete the retransform entry corresponding to this class +* Re-trigger retransform + +> If you do not clear all retransform entries and trigger retransform again, the retransformed classes will still take effect when arthas stop. + +### Use with the jad/mc command + +```bash +jad --source-only com.example.demo.arthas.user.UserController > /tmp/UserController.java + +mc /tmp/UserController.java -d /tmp + +retransform /tmp/com/example/demo/arthas/user/UserController.class +``` + +* Use `jad` command to decompile bytecode, and then you can use other editors, such as vim to modify the source code. +* `mc` command to compile the modified code +* Load new bytecode with `retransform` command + +### Tips for uploading .class files to the server + +The `mc` command may fail. You can modify the code locally, compile it, and upload it to the server. Some servers do not allow direct uploading files, you can use the `base64` command to bypass. + +1. Convert the `.class` file to base64 first, then save it as result.txt + + ```bash + Base64 < Test.class > result.txt + ``` + +2. Login the server, create and edit `result.txt`, copy the local content, paste and save + +3. Restore `result.txt` on the server to `.class` + + ``` + Base64 -d < result.txt > Test.class + ``` + +4. Use the md5 command to verify that the `.class` files are consistent. + + +### Restrictions of the retransform command + +* New field/method is not allowed +* The function that is running, no exit can not take effect, such as the new `System.out.println` added below, only the `run()` function will take effect. + + ```java + public class MathGame { + public static void main(String[] args) throws InterruptedException { + MathGame game = new MathGame(); + while (true) { + game.run(); + TimeUnit.SECONDS.sleep(1); + // This doesn't work because the code keeps running in while + System.out.println("in loop"); + } + } + + public void run() throws InterruptedException { + // This works because the run() function ends completely every time + System.out.println("call run()"); + try { + int number = random.nextInt(); + List primeFactors = primeFactors(number); + print(number, primeFactors); + + } catch (Exception e) { + System.out.println(String.format("illegalArgumentCount:%3d, ", illegalArgumentCount) + e.getMessage()); + } + } +``` \ No newline at end of file diff --git a/site/src/site/sphinx/en/sc.md b/site/src/site/sphinx/en/sc.md index 09761d9e5..6de5d9d07 100644 --- a/site/src/site/sphinx/en/sc.md +++ b/site/src/site/sphinx/en/sc.md @@ -39,7 +39,7 @@ sc ```bash $ sc -d demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false @@ -67,7 +67,7 @@ sc ```bash $ sc -d -f demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false diff --git a/site/src/site/sphinx/en/session.md b/site/src/site/sphinx/en/session.md new file mode 100644 index 000000000..3597c76b2 --- /dev/null +++ b/site/src/site/sphinx/en/session.md @@ -0,0 +1,21 @@ +session +=== + +examines the current session,show the current binded processId and the sessionId. + +> if exits tunnel server,it will also show agentId、tunnelServerUrl、connected status. +> +> if exits statUrl,it will also show statUrl. + + + +### Usage + +```bash +$ session + Name Value +-------------------------------------------------- + JAVA_PID 14584 + SESSION_ID c2073d3b-443a-4a9b-9249-0c5d24a5756c +``` + diff --git a/site/src/site/sphinx/en/spring-boot-starter.md b/site/src/site/sphinx/en/spring-boot-starter.md index 49ac6a552..d4b711f02 100644 --- a/site/src/site/sphinx/en/spring-boot-starter.md +++ b/site/src/site/sphinx/en/spring-boot-starter.md @@ -29,6 +29,8 @@ arthas.tunnel-server=ws://47.75.156.201:7777/ws All supported configuration: [Reference](https://github.com/alibaba/arthas/blob/master/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java) +> By default, arthas-spring-boot-starter will disable the `stop` command. + Reference: [Arthas Properties](arthas-properties.md) ### View Endpoint Information @@ -75,4 +77,16 @@ public class ArthasAttachExample { } } -``` \ No newline at end of file +``` + + +You can also configure properties: + +```java + HashMap configMap = new HashMap(); + configMap.put("arthas.appName", "demo"); + configMap.put("arthas.tunnelServer", "ws://127.0.0.1:7777/ws"); + ArthasAgent.attach(configMap); +``` + +> Note that the configuration must be `camel case`, which is different from the `-` style of spring boot. Only the spring boot application supports both `camel case` and `-` style configuration. \ No newline at end of file diff --git a/site/src/site/sphinx/en/stack.md b/site/src/site/sphinx/en/stack.md index 2b8e8bba0..904f2aaea 100644 --- a/site/src/site/sphinx/en/stack.md +++ b/site/src/site/sphinx/en/stack.md @@ -29,7 +29,7 @@ Pls. refer to [core parameters in expression](advice-class.md) for more details. #### Start Demo -Start `arthas-demo` in [Quick Start](quick-start.md). +Start `math-game` in [Quick Start](quick-start.md). #### stack diff --git a/site/src/site/sphinx/en/stop.md b/site/src/site/sphinx/en/stop.md new file mode 100644 index 000000000..84b3f71cc --- /dev/null +++ b/site/src/site/sphinx/en/stop.md @@ -0,0 +1,7 @@ +Stop +=== + +terminates the Arthas server, all the Arthas clients connecting to this server will be disconnected. + +> the class redefined by redefine command will not be reset. + diff --git a/site/src/site/sphinx/en/trace.md b/site/src/site/sphinx/en/trace.md index 55b091cc3..bbeb5032e 100644 --- a/site/src/site/sphinx/en/trace.md +++ b/site/src/site/sphinx/en/trace.md @@ -33,16 +33,17 @@ Many times what we are interested is the exact trace result when the method call ### Notice -`trace` is handy to help discovering and locating the performance flaws in your system, but pls. note Arthas can only trace the first level method call each time. +* `trace` is handy to help discovering and locating the performance flaws in your system, but pls. note Arthas can only trace the first level method call each time. +* After version 3.3.0, you can use the Dynamic Trace feature to add new matching classes/methods, see the following example. -After version 3.3.0, you can use the Dynamic Trace feature to add new matching classes/methods, see the following example. +* Currently `trace java.lang.Thread getName` is not supported, please refer to issue: [#1610](https://github.com/alibaba/arthas/issues/1610), considering that it is not very necessary and it is difficult to repair , So it won’t be fixed for now ### Usage #### Start Demo -Start `arthas-demo` in [Quick Start](quick-start.md). +Start `math-game` in [Quick Start](quick-start.md). #### Trace method @@ -59,6 +60,7 @@ Affect(class-cnt:1 , method-cnt:1) cost in 28 ms. `---[0.03752ms] demo.MathGame:primeFactors() #24 [throws Exception] ``` +> The `#24` in the result indicates that in the run function, the `primeFactors()` function was called on line `24` of the source file. #### Trace times limit @@ -141,11 +143,21 @@ Trace -E com.test.ClassA|org.test.ClassB method1|method2|method3 ``` +#### Exclude the specified class + +> The watch/trace/monitor/stack/tt commands all support the `--exclude-class-pattern` parameter + +Use the `--exclude-class-pattern` parameter to exclude the specified class, for example: + +```bash +watch javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter +``` + #### Dynamic trace > Supported since version 3.3.0. -Open terminal 1, trace the `run` method, and you can see the printout `listenerId: 1` . +Open terminal 1, trace the `run` method in the above demo, and you can see the printout `listenerId: 1` . ```bash [arthas@59161]$ trace demo.MathGame run @@ -187,4 +199,42 @@ At terminal 1, you can see that the trace result has increased by one layer: `---[0.084025ms] demo.MathGame:print() #25 ``` -Dynamic trace by specifying `listenerId`, you can go deeper and deeper. In addition, commands such as `watch`/`tt`/`monitor` also support similar functionality. \ No newline at end of file +Dynamic trace by specifying `listenerId`, you can go deeper and deeper. In addition, commands such as `watch`/`tt`/`monitor` also support similar functionality. + + +### Trace result time inaccuracy problem + +For example, in the following result: `0.705196 > (0.152743 + 0.145825)` + +```bash +$ trace demo.MathGame run -n 1 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 66 ms, listenerId: 1 +`---ts=2021-02-08 11:27:36;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@232204a1 + `--[0.705196ms] demo.MathGame:run() + +---[0.152743ms] demo.MathGame:primeFactors() #24 + `--[0.145825ms] demo.MathGame:print() #25 +``` + +So where is the rest of the time consumed? + +1. Methods that are not traced to. For example, methods under `java.*` are ignored by default. This can be printed out by adding the `-skipJDKMethod false` parameter. + + ```bash + $ trace demo.MathGame run --skipJDKMethod false + Press Q or Ctrl+C to abort. + Affect(class count: 1 , method count: 1) cost in 35 ms, listenerId: 2 + `---ts=2021-02-08 11:27:48;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@232204a1 + `--[0.810591ms] demo.MathGame:run() + +--[0.034568ms] java.util.Random:nextInt() #23 + +---[0.119367ms] demo.MathGame:timeFactors() #24 [throws Exception] + +---[0.017407ms] java.lang.StringBuilder:() #28 + +--[0.127922ms] java.lang.String:format() #57 + +---[min=0.01419ms,max=0.020221ms,total=0.034411ms,count=2] java.lang.StringBuilder:append() #57 + +--[0.021911ms] java.lang.Exception:getMessage() #57 + +---[0.015643ms] java.lang.StringBuilder:toString() #57 + `--[0.086622ms] java.io.PrintStream:println() #57 + ``` +2. Instruction consumption. For example, instructions such as `i++`, `getfield`, etc. + +3. Possible JVM pause during code execution, such as GC, entering synchronization blocks, etc. diff --git a/site/src/site/sphinx/en/tt.md b/site/src/site/sphinx/en/tt.md index 6c0845af6..fb391762e 100644 --- a/site/src/site/sphinx/en/tt.md +++ b/site/src/site/sphinx/en/tt.md @@ -16,7 +16,7 @@ With the help of `tt` (*TimeTunnel*), you can check the contexts of the methods #### Start Demo -Start `arthas-demo` in [Quick Start](quick-start.md). +Start `math-game` in [Quick Start](quick-start.md). #### Record method calls @@ -127,7 +127,7 @@ $ tt -i 1003 Affect(row-cnt:1) cost in 11 ms. ``` -### Replay record +#### Replay record Since Arthas stores the context of the call, you can even *replay* the method calling afterwards with extra option `-p` to replay the issue for advanced troubleshooting, option `--replay-times` define the replay execution times, option `--replay-interval` define the interval(unit in ms,with default value 1000) of replays @@ -152,13 +152,50 @@ Time fragment[1004] successfully replayed. Affect(row-cnt:1) cost in 14 ms. ``` +#### Watch express + +`-w, --watch-express` watch the time fragment by ognl express. + +* You can used all variables in [fundamental fields in expressions](advice-class.md) for the watch express。 + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w 'target.illegalArgumentCount' -x 1 -i 1000 +@Integer[60] +Affect(row-cnt:1) cost in 7 ms. +``` + +* Get a static field and calling a static method + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w '@demo.MathGame@random.nextInt(100)' -x 1 -i 1000 +@Integer[46] +``` + +Note that `com.taobao.arthas.core.advisor.Advice#getLoader` is used here, and that it is better to use the exact `classloader` [ognl](ognl.md). + + +Advanced usage [get spring context to call the bean method](https://github.com/alibaba/arthas/issues/482) + + F.Y.I 1. **Loss** of the `ThreadLocal` Arthas save params into an array, then invoke the method with the params again. The method execute in another thread, so the `ThreadLocal` **lost**. -1. params may be modified +2. params may be modified Arthas save params into an array, they are object references. The Objects may be modified by other code. diff --git a/site/src/site/sphinx/en/tunnel.md b/site/src/site/sphinx/en/tunnel.md new file mode 100644 index 000000000..3318cea7b --- /dev/null +++ b/site/src/site/sphinx/en/tunnel.md @@ -0,0 +1,115 @@ +Arthas Tunnel +=== + + +Manage/connect multiple Agents remotely via Arthas Tunnel Server/Client. + +For example, in streaming computing, Java processes can be started on different machines, and it can be difficult to use Arthas to diagnose them, because the user usually does not have access to the machine. + +In this case, Arthas Tunnel Server/Client can be used. + +Reference: +* [Web Console](web-console.md) +* [Arthas Spring Boot Starter](spring-boot-starter.md) + +### Download and deploy arthas tunnel server + +[https://github.com/alibaba/arthas/releases](https://github.com/alibaba/arthas/releases) + +Arthas tunnel server is a spring boot fat jar application, start with the `java -jar` command: + +```bash +java -jar arthas-tunnel-server.jar +``` + +By default, the web port of the arthas tunnel server is `8080`, and the port connected by the arthas agent is `7777`. + +Once started, you can go to [http://127.0.0.1:8080/](http://127.0.0.1:8080/) and connect to the registered arthas agent via `agentId`. + +Through Spring Boot's Endpoint, you can view the specific connection information: [http://127.0.0.1:8080/actuator/arthas](http://127.0.0.1:8080/actuator/arthas), the login user name is `arthas`, and the password can be found in the log of arthas tunnel server, for example: + +``` +32851 [main] INFO o.s.b.a.s.s.UserDetailsServiceAutoConfiguration + +Using generated security password: f1dca050-3777-48f4-a577-6367e55a78a2 +``` + +### Connecting to the tunnel server when starting arthas + + +When starting arthas, you can use the `--tunnel-server` parameter, for example: + +```bash +as.sh --tunnel-server 'ws://127.0.0.1:7777/ws' +``` + +You can also use the following test address (not guaranteed to be available all the time): + +```bash +as.sh --tunnel-server 'ws://47.75.156.201:80/ws' +``` + +* You can specify the agentId by the `--agent-id` parameter. By default, a random ID is generated. + +After Arthas attach succeeds, the agentId will be printed, such as: + +```bash + ,---. ,------. ,--------.,--. ,--. ,---. ,---. + / O \ | .--. ''--. .--'| '--' | / O \ ' .-' +| .-. || '--'.' | | | .--. || .-. |`. `-. +| | | || |\ \ | | | | | || | | |.-' | +`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' + + +wiki https://arthas.aliyun.com/doc +tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html +version 3.1.2 +pid 86183 +time 2019-08-30 15:40:53 +id URJZ5L48RPBR2ALI5K4V +``` + +If the connection is not connected to the tunnel server at startup, you can also obtain the agentId through the `session` command after reconnection succeeds: + +```bash +[arthas@86183]$ session + Name Value +----------------------------------------------------- + JAVA_PID 86183 + SESSION_ID f7273eb5-e7b0-4a00-bc5b-3fe55d741882 + AGENT_ID URJZ5L48RPBR2ALI5K4V + TUNNEL_SERVER ws://47.75.156.201:80/ws +``` + + +For the above example, go to [http://47.75.156.201/arthas/?port=80](http://47.75.156.201/arthas/?port=80) in the browser and input the `agentId` to connect to arthas on remote machine. + + +![](_static/arthas-tunnel-server.png) + + +### Best practices + +> Note that the agentId must be unique, otherwise it will conflict on the tunnel server and not work properly. + +If the arthas agent is configured with `appName`, the generated agentId will be prefixed with `appName`. + +For example, if you add the startup parameter `as.sh --tunnel-server 'ws://127.0.0.1:7777/ws' --app-name demoapp`, the generated agentId might be `demoapp_URJZ5L48RPBR2ALI5K4V`. + +Tunnel server will use `_` as a delimiter to extract `appName`, which is convenient to manage by application. + +> Alternatively, you can configure `appName` in `arthas.properties` in the unzipped arthas directory, or in `application.properties` of the spring boot application. + + +### Cluster Management + +If you want to deploy multiple tunnel servers, you can use nginx for forwarding and redis to store agent information. + + +### How arthas tunnel server works + +``` +browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent +``` + +[tunnel-server/README.md](https://github.com/alibaba/arthas/blob/master/tunnel-server/README.md#) diff --git a/site/src/site/sphinx/en/version.md b/site/src/site/sphinx/en/version.md new file mode 100644 index 000000000..6619b897d --- /dev/null +++ b/site/src/site/sphinx/en/version.md @@ -0,0 +1,12 @@ +version +=== + +prints out Arthas's version. + +### Usage + +```bash +$ version + 3.5.1 +``` + diff --git a/site/src/site/sphinx/en/vmtool.md b/site/src/site/sphinx/en/vmtool.md new file mode 100644 index 000000000..b30dde9db --- /dev/null +++ b/site/src/site/sphinx/en/vmtool.md @@ -0,0 +1,82 @@ +vmtool +=== + +> @since 3.5.1 +[`vmtool` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=en&id=command-vmtool) + +`vmtool` uses the `JVMTI` to support `getInstances` in jvm and `forceGc`. + +* [JVM Tool Interface](https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html) + +### getInstances + +```bash +$ vmtool --action getInstances --className java.lang.String --limit 10 +@String[][ + @String[com/taobao/arthas/core/shell/session/Session], + @String[com.taobao.arthas.core.shell.session.Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/], + @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], + @String[java/util/concurrent/locks/LockSupport], +] +``` + +> Through the `--limit` parameter, you can limit the number of return values to avoid pressure on the JVM when obtaining large data. The default value of limit is 10. + +### Specify classloader name + +```bash +vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext +``` + + +### Specify classloader hash + +The classloader that loads the class can be found through the `sc` command. + +```bash +$ sc -d org.springframework.context.ApplicationContext + class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext + code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/ + name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext +... + class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2 + +-sun.misc.Launcher$AppClassLoader@75b84c92 + +-sun.misc.Launcher$ExtClassLoader@4f023edb + classLoaderHash 19469ea2 +``` + +Then use the `-c`/`--classloader` parameter to specify: + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext +``` + +### Specify the number of expanded layers of returned results + +> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. + +> The expansion level of the result can be specified by the `-x`/`--expand` parameter, the default value is 1. + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2 +``` + +### Execute expression + +> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. The specified expression can be executed through the `--express` parameter. + +```bash +vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext --express'instances[0].getBeanDefinitionNames()' +``` + +### Force GC + +```bash +vmtool --action forceGc +``` \ No newline at end of file diff --git a/site/src/site/sphinx/en/watch.md b/site/src/site/sphinx/en/watch.md index d248e7f39..c95cfbfab 100644 --- a/site/src/site/sphinx/en/watch.md +++ b/site/src/site/sphinx/en/watch.md @@ -41,7 +41,7 @@ Advanced: #### Start Demo -Start `arthas-demo` in [Quick Start](quick-start.md). +Start `math-game` in [Quick Start](quick-start.md). #### Check the `out parameters` and `return value` @@ -51,7 +51,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 44 ms. ts=2018-12-03 19:16:51; [cost=1.280502ms] result=@ArrayList[ @Object[][ - @Integer[535629513], + @Integer[1], ], @ArrayList[ @Integer[3], @@ -90,7 +90,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 46 ms. ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -100,7 +100,7 @@ ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ ] ts=2018-12-03 19:29:54; [cost=4.277392ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -133,7 +133,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 58 ms. ts=2018-12-03 19:34:19; [cost=0.587833ms] result=@ArrayList[ @Object[][ - @Integer[47816758], + @Integer[1], ], @MathGame[ random=@Random[ @@ -199,7 +199,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 66 ms. ts=2018-12-03 19:40:28; [cost=2112.168897ms] result=@ArrayList[ @Object[][ - @Integer[2141897465], + @Integer[1], ], @ArrayList[ @Integer[5], @@ -234,3 +234,77 @@ Affect(class-cnt:1 , method-cnt:1) cost in 67 ms. ts=2018-12-03 20:04:34; [cost=131.303498ms] result=@Integer[8] ts=2018-12-03 20:04:35; [cost=0.961441ms] result=@Integer[8] ``` + +#### Get a static field and calling a static method + +```bash +watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -v -n 1 -x 2 +[arthas@6527]$ watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -n 1 -x 2 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 5) cost in 34 ms, listenerId: 3 +ts=2021-01-05 21:35:20; [cost=0.173966ms] result=@ArrayList[ + @Object[][ + @Integer[-138282], + ], + @Integer[89], +] +``` + +* Note that here you use `Thread.currentThread().getContextClassLoader()` to load, and it is better to use the exact `classloader` [ognl](ognl.md). + + +#### Exclude the specified class + +> The watch/trace/monitor/stack/tt commands all support the `--exclude-class-pattern` parameter + +Use the `--exclude-class-pattern` parameter to exclude the specified class, for example: + +```bash +watch javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter +``` +#### Does not match subclass + +By default, the watch/trace/monitor/stack/tt commands will match subclass. If you don't want to match, you can turn it off. + +```bash +options disable-sub-class true +``` + + +#### Use the -v parameter to print more information + +> The watch/trace/monitor/stack/tt commands all support the `-v` parameter. + +When the command is executed, there is no output result. There are two possibilities: + +1. The matched function is not executed +2. The result of the conditional expression is false + +But the user cannot tell which situation is. + +Using the `-v` option, the specific value and execution result of `Condition express` will be printed for easy confirmation. + +such as: + +``` +$ watch -v -x 2 demo.MathGame print 'params' 'params[0] > 100000' +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 29 ms, listenerId: 11 +Condition express: params[0] > 100000 , result: false +Condition express: params[0] > 100000 , result: false +Condition express: params[0] > 100000 , result: true +ts=2020-12-02 22:38:56; [cost=0.060843ms] result=@Object[][ + @Integer[1], + @ArrayList[ + @Integer[200033], + ], +] +Condition express: params[0] > 100000 , result: true +ts=2020-12-02 22:38:57; [cost=0.052877ms] result=@Object[][ + @Integer[1], + @ArrayList[ + @Integer[29], + @Integer[4243], + ], +] +``` \ No newline at end of file diff --git a/site/src/site/sphinx/en/web-console.md b/site/src/site/sphinx/en/web-console.md index b81073543..cbf952cef 100644 --- a/site/src/site/sphinx/en/web-console.md +++ b/site/src/site/sphinx/en/web-console.md @@ -15,88 +15,8 @@ The user can fill in the IP and connect the remote arthas on other machines. If you have suggestions for the Web Console, please leave a message here: [https://github.com/alibaba/arthas/issues/15](https://github.com/alibaba/arthas/issues/15) -### Connect remote arthas through arthas tunnel server - -#### Download and deploy arthas tunnel server - -[https://github.com/alibaba/arthas/releases](https://github.com/alibaba/arthas/releases) - -Arthas tunnel server is a spring boot fat jar application, start with the `java -jar` command: - -```bash -java -jar arthas-tunnel-server.jar -``` - -By default, the web port of the arthas tunnel server is `8080`, and the port connected by the arthas agent is `7777`. - -Once started, you can go to [http://127.0.0.1:8080/](http://127.0.0.1:8080/) and connect to the registered arthas agent via `agentId`. - -Through Spring Boot's Endpoint, you can view the specific connection information: [http://127.0.0.1:8080/actuator/arthas](http://127.0.0.1:8080/actuator/arthas), the login user name is `arthas`, and the password can be found in the log of arthas tunnel server, for example: - -``` -32851 [main] INFO o.s.b.a.s.s.UserDetailsServiceAutoConfiguration - -Using generated security password: f1dca050-3777-48f4-a577-6367e55a78a2 -``` - -#### Connecting to the tunnel server when starting arthas - - -When starting arthas, you can use the `--tunnel-server` parameter, for example: - -```bash -as.sh --tunnel-server 'ws://127.0.0.1:7777/ws' -``` - -You can also use the following test address (not guaranteed to be available all the time): +* Copy and paste shortcut keys in Web Console: [https://github.com/alibaba/arthas/issues/1056](https://github.com/alibaba/arthas/issues/1056) -```bash -as.sh --tunnel-server 'ws://47.75.156.201:7777/ws' -``` - -* You can specify the agentId by the `--agent-id` parameter. By default, a random ID is generated. - -After Arthas attach succeeds, the agentId will be printed, such as: - -```bash - ,---. ,------. ,--------.,--. ,--. ,---. ,---. - / O \ | .--. ''--. .--'| '--' | / O \ ' .-' -| .-. || '--'.' | | | .--. || .-. |`. `-. -| | | || |\ \ | | | | | || | | |.-' | -`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' - - -wiki https://arthas.aliyun.com/doc -tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html -version 3.1.2 -pid 86183 -time 2019-08-30 15:40:53 -id URJZ5L48RPBR2ALI5K4V -``` - -If the connection is not connected to the tunnel server at startup, you can also obtain the agentId through the `session` command after reconnection succeeds: - -```bash -[arthas@86183]$ session - Name Value ------------------------------------------------------ - JAVA_PID 86183 - SESSION_ID f7273eb5-e7b0-4a00-bc5b-3fe55d741882 - AGENT_ID URJZ5L48RPBR2ALI5K4V - TUNNEL_SERVER ws://47.75.156.201:7777/ws -``` - - -For the above example, go to [http://47.75.156.201:8080/](http://47.75.156.201:8080/) in the browser and input the `agentId` to connect to arthas on remote machine. - - -![](_static/arthas-tunnel-server.png) - - -#### How arthas tunnel server works - -``` -browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent -``` +### Connect remote arthas through arthas tunnel server -[tunnel-server/README.md](https://github.com/alibaba/arthas/blob/master/tunnel-server/README.md#) \ No newline at end of file +[Arthas Tunnel](tunnel.md) \ No newline at end of file diff --git a/site/src/site/sphinx/faq.md b/site/src/site/sphinx/faq.md new file mode 100644 index 000000000..be6021024 --- /dev/null +++ b/site/src/site/sphinx/faq.md @@ -0,0 +1,92 @@ + +## FAQ + + +> 不在本列表里的问题,请到issue里搜索。 [https://github.com/alibaba/arthas/issues](https://github.com/alibaba/arthas/issues) + + +##### 日志文件在哪里? + +日志文件路径: `~/logs/arthas/arthas.log` +##### Arthas attach之后对原进程性能有多大的影响 + +[https://github.com/alibaba/arthas/issues/44](https://github.com/alibaba/arthas/issues/44) + + +##### target process not responding or HotSpot VM not loaded + +com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded + +1. 检查当前用户和目标java进程是否一致。如果不一致,则切换到同一用户。JVM只能attach同样用户下的java 进程。 +2. 尝试使用 `jstack -l $pid`,如果进程没有反应,则说明进程可能假死,无法响应JVM attach信号。所以同样基于attach机制的Arthas无法工作。尝试使用`jmap` heapdump后分析。 +3. 尝试按[quick-start](quick-start.md)里的方式attach math-game。 +4. 更多情况参考: [https://github.com/alibaba/arthas/issues/347](https://github.com/alibaba/arthas/issues/347) +##### trace/watch等命令能否增强jdk里的类? + +默认情况下会过滤掉`java.`开头的类,但可以通过参数开启。 + +```bash +options unsafe true +``` + +更多参考 [options](options.md) + +##### 怎么以`json`格式查看结果 + +```bash +options json-format true +``` + +更多参考 [options](options.md) + + +##### Arthas能否跟踪 native 函数 + +不能。 + + +##### 能不能查看内存里某个变量的值 + +1. 可以使用[`vmtool`](vmtool.md)命令。 +2. 可以用一些技巧,用[`tt`](tt.md)命令拦截到对象,或者从静态函数里取到对象。 + + +##### 方法同名过滤 + +同名方法过滤可以通过匹配表达式,可以使用[表达式核心变量](advice-class.md)中所有变量作为已知条件,可以通过判断参数个数`params.length ==1`, 参数类型`params[0] instanceof java.lang.Integer`、返回值类型 `returnObj instanceof java.util.List` 等等一种或者多种组合进行过滤。 + +可以使用 `-v` 查看观察匹配表达式的执行结果 [https://github.com/alibaba/arthas/issues/1348](https://github.com/alibaba/arthas/issues/1348) + +例子[math-game](quick-start.md) + +```bash +watch demo.MathGame primeFactors '{params,returnObj,throwExp}' 'params.length >0 && returnObj instanceof java.util.List' -v +``` + +##### 怎么watch、trace 构造函数 ? + +```bash +watch demo.MathGame '{params,returnObj,throwExp}' -v +``` + + +##### java.lang.ClassFormatError: null、skywalking arthas 兼容使用 + +当出现这个错误日志`java.lang.ClassFormatError: null`,通常情况下都是被其他字节码工具修改过与arthas修改字节码不兼容。 + +比如: 使用 skywalking V8.1.0 以下版本 [无法trace、watch 被skywalking agent 增强过的类](https://github.com/alibaba/arthas/issues/1141), V8.1.0 以上版本可以兼容使用,更多参考skywalking配置 [skywalking compatible with other javaagent bytecode processing](https://github.com/apache/skywalking/blob/v8.1.0/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md)。 + + +##### Arthas能不能离线使用 + +可以。下载全量包解压即可,参考: [下载](download.md)。 + +##### Attach docker/k8s 里的 pid 为 1 的进程失败 + +参考: [https://github.com/alibaba/arthas/issues/362#issuecomment-448185416](https://github.com/alibaba/arthas/issues/362#issuecomment-448185416) + +##### 为什么下载了新版本的Arthas,连接的却是旧版本? + +比如启动的 `as.sh/arthas-boot.jar` 版本是3.5.* 的,但是连接上之后,打印的arthas版本是 3.4.* 的。 + +可能是之前使用旧版本的arthas诊断过目标进程。可以先执行`stop`停止掉旧版本的arthas,再重新使用新版本attach。 diff --git a/site/src/site/sphinx/help.md b/site/src/site/sphinx/help.md new file mode 100644 index 000000000..e20034a10 --- /dev/null +++ b/site/src/site/sphinx/help.md @@ -0,0 +1,87 @@ +help +=== + +查看命令帮助信息,可以查看当前arthas版本支持的指令,或者查看具体指令的使用说明。 + +> [help 指令]的等同于[指令 -help],都是查看具体指令的使用说明。 + +### 参数说明 + +| 参数名称 | 参数说明 | +| -------: | :--------------------------------------- | +| 不接参数 | 查询当前arthas版本支持的指令以及指令描述 | +| [name:] | 查询具体指令的使用说明 | + +### 使用参考 + +``` +$ help + NAME DESCRIPTION + help Display Arthas Help + auth Authenticates the current session + keymap Display all the available keymap for the specified connection. + sc Search all the classes loaded by JVM + sm Search the method of classes loaded by JVM + classloader Show classloader info + jad Decompile class + getstatic Show the static field of a class + monitor Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc. + stack Display the stack trace for the specified class and method + thread Display thread info, thread stack + trace Trace the execution time of specified method invocation. + watch Display the input/output parameter, return object, and thrown exception of specified method invocation + tt Time Tunnel + jvm Display the target JVM information + perfcounter Display the perf counter information. + ognl Execute ognl expression. + mc Memory compiler, compiles java files into bytecode and class files in memory. + redefine Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition...) + retransform Retransform classes. @see Instrumentation#retransformClasses(Class...) + dashboard Overview of target jvm's thread, memory, gc, vm, tomcat info. + dump Dump class byte array from JVM + heapdump Heap dump + options View and change various Arthas options + cls Clear the screen + reset Reset all the enhanced classes + version Display Arthas version + session Display current session information + sysprop Display, and change the system properties. + sysenv Display the system env. + vmoption Display, and update the vm diagnostic options. + logger Print logger info, and update the logger level + history Display command history + cat Concatenate and print files + base64 Encode and decode using Base64 representation + echo write arguments to the standard output + pwd Return working directory name + mbean Display the mbean information + grep grep command for pipes. + tee tee command for pipes. + profiler Async Profiler. https://github.com/jvm-profiling-tools/async-profiler + stop Stop/Shutdown Arthas server and exit the console. + + +``` + +``` + $ help dashboard + USAGE: + dashboard [-h] [-i ] [-n ] + + SUMMARY: + Overview of target jvm's thread, memory, gc, vm, tomcat info. + + EXAMPLES: + dashboard + dashboard -n 10 + dashboard -i 2000 + + WIKI: + https://arthas.aliyun.com/doc/dashboard + + OPTIONS: + -h, --help this help + -i, --interval The interval (in ms) between two executions, default is 5000 ms. + -n, --number-of-execution The number of times this command will be executed. +``` + diff --git a/site/src/site/sphinx/history.md b/site/src/site/sphinx/history.md new file mode 100644 index 000000000..b555b4e96 --- /dev/null +++ b/site/src/site/sphinx/history.md @@ -0,0 +1,31 @@ +history +=== + +打印命令历史。 + +> 历史指令会通过一个名叫history的文件持久化,所以history指令可以查看当前arthas服务器的所有历史命令,而不仅只是当前次会话使用过的命令。 + +### 参数说明 + +| 参数名称 | 参数说明 | +| -------: | :-------------------- | +| [c:] | 清空历史指令 | +| [n:] | 显示最近执行的n条指令 | + +### 使用参考 + +``` +#查看最近执行的3条指令 +$ history 3 + 269 thread + 270 cls + 271 history 3 +``` + +``` + #清空指令 + $ history -c + $ history 3 + 1 history 3 +``` + diff --git a/site/src/site/sphinx/http-api.md b/site/src/site/sphinx/http-api.md index 4ff6e0ece..f092656ee 100644 --- a/site/src/site/sphinx/http-api.md +++ b/site/src/site/sphinx/http-api.md @@ -434,6 +434,10 @@ curl -Ss -XPOST http://localhost:8563/api -d ''' } ``` +### 鉴权 + +参考: [auth](auth.md) + ### Web UI ![](_static/arthas-web-ui.png "arthas web ui") diff --git a/site/src/site/sphinx/idea-plugin.md b/site/src/site/sphinx/idea-plugin.md index 39637750e..b4cc62a82 100644 --- a/site/src/site/sphinx/idea-plugin.md +++ b/site/src/site/sphinx/idea-plugin.md @@ -5,7 +5,7 @@ IDEA Plugin * Jetbrains 插件获取地址: [https://plugins.jetbrains.com/plugin/13581-arthas-idea](https://plugins.jetbrains.com/plugin/13581-arthas-idea) -* 使用文档:[https://www.yuque.com/docs/share/fa77c7b4-c016-4de6-9fa3-58ef25a97948?#](https://www.yuque.com/docs/share/fa77c7b4-c016-4de6-9fa3-58ef25a97948?#) +* 使用文档:[https://www.yuque.com/arthas-idea-plugin](https://www.yuque.com/arthas-idea-plugin) * 源码地址: [https://github.com/WangJi92/arthas-idea-plugin](https://github.com/WangJi92/arthas-idea-plugin) diff --git a/site/src/site/sphinx/index.md b/site/src/site/sphinx/index.md index d78950647..5cf059fd2 100644 --- a/site/src/site/sphinx/index.md +++ b/site/src/site/sphinx/index.md @@ -18,31 +18,35 @@ Arthas 用户文档 0. 是否有一个全局视角来查看系统的运行状况? 0. 有什么办法可以监控到JVM的实时运行状态? 0. 怎么快速定位应用的热点,生成火焰图? +0. 怎样直接从JVM内查找某个类的实例? `Arthas`支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。 + **如果您在使用Arthas,请让我们知道,您的使用对我们非常重要:[查看](https://github.com/alibaba/arthas/issues/111)** Contents -------- * [首页](https://arthas.aliyun.com/) -* [技术征文!](https://developer.aliyun.com/article/751641) +* [技术分享征文!](https://developer.aliyun.com/article/751641) * [English Docs](https://arthas.aliyun.com/doc/en/) -* [在线教程(推荐)](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn) +* [在线教程(katacoda)](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn) +* [在线教程(阿里云)](https://start.aliyun.com/handson-lab?category=arthas) * [安装](install-detail.md) * [下载](download.md) * [快速入门](quick-start.md) * [进阶使用](advanced-use.md) * [命令列表](commands.md) * [WebConsole](web-console.md) +* [Arthas Tunnel](tunnel.md) * [Http API](http-api.md) * [Docker](docker.md) * [Arthas Spring Boot Starter](spring-boot-starter.md) * [IDEA 插件](idea-plugin.md) * [用户案例](https://github.com/alibaba/arthas/issues?q=label%3Auser-case) -* [常见问题](https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered) -* [Fork me at GitHub](https://github.com/alibaba/arthas) +* [FAQ/常见问题](faq.md) +* [Star me at GitHub](https://github.com/alibaba/arthas) * [编译调试/参与贡献](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md#) * [Release Notes](https://github.com/alibaba/arthas/releases) * [QQ群/钉钉群](contact-us.md) diff --git a/site/src/site/sphinx/jad.md b/site/src/site/sphinx/jad.md index 5fea91ed9..5cc57e213 100644 --- a/site/src/site/sphinx/jad.md +++ b/site/src/site/sphinx/jad.md @@ -21,7 +21,7 @@ jad ### 使用参考 -#### 编译`java.lang.String` +#### 反编译`java.lang.String` ```java $ jad java.lang.String @@ -31,35 +31,39 @@ ClassLoader: Location: -/* -* Decompiled with CFR 0_132. -*/ -package java.lang; + /* + * Decompiled with CFR. + */ + package java.lang; -import java.io.ObjectStreamField; + import java.io.ObjectStreamField; + import java.io.Serializable; ... -public final class String -implements Serializable, -Comparable, -CharSequence { - private final char[] value; - private int hash; - private static final long serialVersionUID = -6849794470754667710L; - private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; - public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); - - public String(byte[] arrby, int n, int n2) { - String.checkBounds(arrby, n, n2); - this.value = StringCoding.decode(arrby, n, n2); - } + public final class String + implements Serializable, + Comparable, + CharSequence { + private final char[] value; + private int hash; + private static final long serialVersionUID = -6849794470754667710L; + private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0]; + public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); +... + public String(byte[] byArray, int n, int n2, Charset charset) { +/*460*/ if (charset == null) { + throw new NullPointerException("charset"); + } +/*462*/ String.checkBounds(byArray, n, n2); +/*463*/ this.value = StringCoding.decode(charset, byArray, n, n2); + } ... ``` #### 反编译时只显示源代码 -默认情况下,反编译结果里会带有`ClassLoader`信息,通过`--source-only`选项,可以只打印源代码。方便和[mc](mc.md)/[redefine](redefine.md)命令结合使用。 +默认情况下,反编译结果里会带有`ClassLoader`信息,通过`--source-only`选项,可以只打印源代码。方便和[mc](mc.md)/[retransform](retransform.md)命令结合使用。 -``` +```java $ jad --source-only demo.MathGame /* * Decompiled with CFR 0_132. @@ -85,21 +89,42 @@ public class MathGame { $ jad demo.MathGame main ClassLoader: -+-sun.misc.Launcher$AppClassLoader@3d4eac69 -+-sun.misc.Launcher$ExtClassLoader@66350f69 ++-sun.misc.Launcher$AppClassLoader@232204a1 + +-sun.misc.Launcher$ExtClassLoader@7f31245a + +Location: +/private/tmp/math-game.jar + + public static void main(String[] args) throws InterruptedException { + MathGame game = new MathGame(); + while (true) { +/*16*/ game.run(); +/*17*/ TimeUnit.SECONDS.sleep(1L); + } + } +``` + +#### 反编译时不显示行号 + +`--lineNumber` 参数默认值为true,显示指定为false则不打印行号。 + +```java +$ jad demo.MathGame main --lineNumber false + +ClassLoader: ++-sun.misc.Launcher$AppClassLoader@232204a1 + +-sun.misc.Launcher$ExtClassLoader@7f31245a Location: -/private/tmp/arthas-demo.jar +/private/tmp/math-game.jar public static void main(String[] args) throws InterruptedException { MathGame game = new MathGame(); - do { + while (true) { game.run(); TimeUnit.SECONDS.sleep(1L); - } while (true); + } } - -Affect(row-cnt:1) cost in 228 ms. ``` #### 反编译时指定ClassLoader diff --git a/site/src/site/sphinx/mc.md b/site/src/site/sphinx/mc.md index a50c5b9a0..937edb320 100644 --- a/site/src/site/sphinx/mc.md +++ b/site/src/site/sphinx/mc.md @@ -1,7 +1,7 @@ mc === -[`mc-redefine`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-mc-redefine) +[`mc-retransform`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-mc-retransform) > Memory Compiler/内存编译器,编译`.java`文件生成`.class`。 @@ -30,6 +30,6 @@ Affect(row-cnt:1) cost in 346 ms mc -d /tmp/output /tmp/ClassA.java /tmp/ClassB.java ``` -编译生成`.class`文件之后,可以结合[redefine](redefine.md)命令实现热更新代码。 +编译生成`.class`文件之后,可以结合[retransform](retransform.md)命令实现热更新代码。 -> 注意,mc命令有可能失败。如果编译失败可以在本地编译好`.class`文件,再上传到服务器。具体参考[redefine](redefine.md)命令说明。 \ No newline at end of file +> 注意,mc命令有可能失败。如果编译失败可以在本地编译好`.class`文件,再上传到服务器。具体参考[retransform](retransform.md)命令说明。 \ No newline at end of file diff --git a/site/src/site/sphinx/options.md b/site/src/site/sphinx/options.md index a5bc4e599..5db02d86e 100644 --- a/site/src/site/sphinx/options.md +++ b/site/src/site/sphinx/options.md @@ -79,3 +79,20 @@ $ options save-result true ---------------------------------------- save-result false true ``` + +### 打开unsafe开关,支持jdk package下的类 + +默认情况下,`watch`/`trace`/`tt`/`trace`/`monitor`等命令不支持`java.*` package下的类。可以设置`unsafe`为true,则可以增强。 + +```bash +$ options unsafe true + NAME BEFORE-VALUE AFTER-VALUE +----------------------------------- + unsafe false true +``` + +```bash +$ watch java.lang.invoke.Invokers callSiteForm +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 61 ms, listenerId: 1 +``` diff --git a/site/src/site/sphinx/profiler.md b/site/src/site/sphinx/profiler.md index 737f540c3..1b97705b4 100644 --- a/site/src/site/sphinx/profiler.md +++ b/site/src/site/sphinx/profiler.md @@ -228,4 +228,9 @@ profiler start --file /tmp/test.jfr 生成的结果可以用支持jfr格式的工具来查看。比如: * JDK Mission Control : https://github.com/openjdk/jmc -* JProfiler : https://github.com/alibaba/arthas/issues/1416 \ No newline at end of file +* JProfiler : https://github.com/alibaba/arthas/issues/1416 + + +### 生成的火焰图里的 unknown + +* https://github.com/jvm-profiling-tools/async-profiler/discussions/409 diff --git a/site/src/site/sphinx/quick-start.md b/site/src/site/sphinx/quick-start.md index 710ba9523..41f1cef66 100644 --- a/site/src/site/sphinx/quick-start.md +++ b/site/src/site/sphinx/quick-start.md @@ -1,16 +1,16 @@ 快速入门 === -## 1. 启动Demo +## 1. 启动math-game ```bash -curl -O https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar +curl -O https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar ``` -`arthas-demo`是一个简单的程序,每隔一秒生成一个随机数,再执行质因数分解,并打印出分解结果。 +`math-game`是一个简单的程序,每隔一秒生成一个随机数,再执行质因数分解,并打印出分解结果。 -`arthas-demo`源代码:[查看](https://github.com/alibaba/arthas/blob/master/demo/src/main/java/demo/MathGame.java) +`math-game`源代码:[查看](https://github.com/alibaba/arthas/blob/master/math-game/src/main/java/demo/MathGame.java) ## 2. 启动arthas @@ -33,10 +33,10 @@ java -jar arthas-boot.jar ```bash $ $ java -jar arthas-boot.jar * [1]: 35542 - [2]: 71560 arthas-demo.jar + [2]: 71560 math-game.jar ``` -Demo进程是第2个,则输入2,再输入`回车/enter`。Arthas会attach到目标进程上,并输出日志: +`math-game`进程是第2个,则输入2,再输入`回车/enter`。Arthas会attach到目标进程上,并输出日志: ```bash [INFO] Try to attach process 71560 @@ -95,7 +95,7 @@ java.home /Library/Java/JavaVir e/jre ``` -## 4. 通过thread命令来获取到`arthas-demo`进程的Main Class +## 4. 通过thread命令来获取到`math-game`进程的Main Class `thread 1`会打印线程ID 1的栈,通常是main函数的线程。 @@ -114,7 +114,7 @@ ClassLoader: +-sun.misc.Launcher$ExtClassLoader@66350f69 Location: -/tmp/arthas-demo.jar +/tmp/math-game.jar /* * Decompiled with CFR 0_132. diff --git a/site/src/site/sphinx/quit.md b/site/src/site/sphinx/quit.md new file mode 100644 index 000000000..10b887d91 --- /dev/null +++ b/site/src/site/sphinx/quit.md @@ -0,0 +1,7 @@ +quit +=== + +退出当前 Arthas 客户端,其他 Arthas 客户端不受影响。等同于**exit**、**logout**、**q**三个指令。 + +> 只是退出当前Arthas客户端,Arthas的服务器端并没有关闭,所做的修改也不会被重置。 + diff --git a/site/src/site/sphinx/redefine.md b/site/src/site/sphinx/redefine.md index 872d74cad..fcfc212d8 100644 --- a/site/src/site/sphinx/redefine.md +++ b/site/src/site/sphinx/redefine.md @@ -1,6 +1,8 @@ redefine === +> 推荐使用 [retransform](retransform.md) 命令 + [`mc-redefine`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-mc-redefine) > 加载外部的`.class`文件,redefine jvm已加载的类。 @@ -9,6 +11,8 @@ redefine ### 常见问题 +> 推荐使用 [retransform](retransform.md) 命令 + * redefine的class不能修改、添加、删除类的field和method,包括方法参数、方法名称及返回值 * 如果mc失败,可以在本地开发环境编译好class文件,上传到目标系统,使用redefine热加载class @@ -28,9 +32,6 @@ redefine |---:|:---| |[c:]|ClassLoader的hashcode| |`[classLoaderClass:]`|指定执行表达式的 ClassLoader 的 class name| -|[p:]|外部的`.class`文件的完整路径,支持多个| - - ### 使用参考 diff --git a/site/src/site/sphinx/retransform.md b/site/src/site/sphinx/retransform.md new file mode 100644 index 000000000..e510ef46e --- /dev/null +++ b/site/src/site/sphinx/retransform.md @@ -0,0 +1,142 @@ +retransform +=== + +[`mc-retransform`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-mc-retransform) + +> 加载外部的`.class`文件,retransform jvm已加载的类。 + +参考:[Instrumentation#retransformClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses-java.lang.Class...-) + + +### 使用参考 + +```bash + retransform /tmp/Test.class + retransform -l + retransform -d 1 # delete retransform entry + retransform --deleteAll # delete all retransform entries + retransform --classPattern demo.* # triger retransform classes + retransform -c 327a647b /tmp/Test.class /tmp/Test\$Inner.class + retransform --classLoaderClass 'sun.misc.Launcher$AppClassLoader' /tmp/Test.class +``` + +### retransform 指定的 .class 文件 + +```bash +$ retransform /tmp/MathGame.class +retransform success, size: 1, classes: +demo.MathGame +``` + +加载指定的 .class 文件,然后解析出class name,再retransform jvm中已加载的对应的类。每加载一个 `.class` 文件,则会记录一个 retransform entry. + +> 如果多次执行 retransform 加载同一个 class 文件,则会有多条 retransform entry. + +### 查看 retransform entry + +```bash +$ retransform -l +Id ClassName TransformCount LoaderHash LoaderClassName +1 demo.MathGame 1 null null +``` + +* TransformCount 统计在 ClassFileTransformer#transform 函数里尝试返回 entry对应的 .class文件的次数,但并不表明transform一定成功。 + +### 删除指定 retransform entry + +需要指定 id: + +```bash +retransform -d 1 +``` + +### 删除所有 retransform entry + +```bash +retransform --deleteAll +``` + +### 显式触发 retransform + +```bash +$ retransform --classPattern demo.MathGame +retransform success, size: 1, classes: +demo.MathGame +``` + +> 注意:对于同一个类,当存在多个 retransform entry时,如果显式触发 retransform ,则最后添加的entry生效(id最大的)。 + +### 消除 retransform 的影响 + +如果对某个类执行 retransform 之后,想消除影响,则需要: + +* 删除这个类对应的 retransform entry +* 重新触发 retransform + +> 如果不清除掉所有的 retransform entry,并重新触发 retransform ,则arthas stop时,retransform过的类仍然生效。 + + +### 结合 jad/mc 命令使用 + +```bash +jad --source-only com.example.demo.arthas.user.UserController > /tmp/UserController.java + +mc /tmp/UserController.java -d /tmp + +retransform /tmp/com/example/demo/arthas/user/UserController.class +``` + +* jad命令反编译,然后可以用其它编译器,比如vim来修改源码 +* mc命令来内存编译修改过的代码 +* 用retransform命令加载新的字节码 + +### 上传 .class 文件到服务器的技巧 + +使用`mc`命令来编译`jad`的反编译的代码有可能失败。可以在本地修改代码,编译好后再上传到服务器上。有的服务器不允许直接上传文件,可以使用`base64`命令来绕过。 + +1. 在本地先转换`.class`文件为base64,再保存为result.txt + + ```bash + base64 < Test.class > result.txt + ``` + +2. 到服务器上,新建并编辑`result.txt`,复制本地的内容,粘贴再保存 + +3. 把服务器上的 `result.txt`还原为`.class` + + ``` + base64 -d < result.txt > Test.class + ``` + +4. 用md5命令计算哈希值,校验是否一致 + +### retransform的限制 + +* 不允许新增加field/method +* 正在跑的函数,没有退出不能生效,比如下面新增加的`System.out.println`,只有`run()`函数里的会生效 + + ```java + public class MathGame { + public static void main(String[] args) throws InterruptedException { + MathGame game = new MathGame(); + while (true) { + game.run(); + TimeUnit.SECONDS.sleep(1); + // 这个不生效,因为代码一直跑在 while里 + System.out.println("in loop"); + } + } + + public void run() throws InterruptedException { + // 这个生效,因为run()函数每次都可以完整结束 + System.out.println("call run()"); + try { + int number = random.nextInt(); + List primeFactors = primeFactors(number); + print(number, primeFactors); + + } catch (Exception e) { + System.out.println(String.format("illegalArgumentCount:%3d, ", illegalArgumentCount) + e.getMessage()); + } + } +``` \ No newline at end of file diff --git a/site/src/site/sphinx/sc.md b/site/src/site/sphinx/sc.md index fc9011433..50a56f49f 100644 --- a/site/src/site/sphinx/sc.md +++ b/site/src/site/sphinx/sc.md @@ -43,7 +43,7 @@ sc ```bash $ sc -d demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false @@ -71,7 +71,7 @@ sc ```bash $ sc -d -f demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false diff --git a/site/src/site/sphinx/session.md b/site/src/site/sphinx/session.md new file mode 100644 index 000000000..957faae5c --- /dev/null +++ b/site/src/site/sphinx/session.md @@ -0,0 +1,22 @@ +session +=== + +查看当前会话的信息,显示当前绑定的pid以及会话id。 + +> 如果配置了tunnel server,会追加打印 代理id、tunnel服务器的url以及连接状态。 +> +> 如果使用了staturl做统计,会追加显示statUrl地址。 + + + +### 使用参考 + +``` +$ session + Name Value +-------------------------------------------------- + JAVA_PID 14584 + SESSION_ID c2073d3b-443a-4a9b-9249-0c5d24a5756c + +``` + diff --git a/site/src/site/sphinx/spring-boot-starter.md b/site/src/site/sphinx/spring-boot-starter.md index 321b22339..a3c623e8b 100644 --- a/site/src/site/sphinx/spring-boot-starter.md +++ b/site/src/site/sphinx/spring-boot-starter.md @@ -17,7 +17,7 @@ Arthas Spring Boot Starter 应用启动后,spring会启动arthas,并且attach自身进程。 -> 一键创建包含 Arthas Spring Boot Starter 的工程:点击 +> 一键创建包含 Arthas Spring Boot Starter 的工程:点击 ### 配置属性 @@ -31,6 +31,8 @@ arthas.tunnel-server=ws://47.75.156.201:7777/ws 全部支持的配置项:[参考](https://github.com/alibaba/arthas/blob/master/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java) +> 默认情况下,arthas-spring-boot-starter会禁掉`stop`命令。 + 参考:[Arthas Properties](arthas-properties.md) ### 查看Endpoint信息 @@ -77,4 +79,15 @@ public class ArthasAttachExample { } } -``` \ No newline at end of file +``` + +也可以配置属性: + +```java + HashMap configMap = new HashMap(); + configMap.put("arthas.appName", "demo"); + configMap.put("arthas.tunnelServer", "ws://127.0.0.1:7777/ws"); + ArthasAgent.attach(configMap); +``` + +> 注意配置必须是`驼峰`的,和spring boot的`-`风格不一样。spring boot应用才同时支持`驼峰` 和 `-`风格的配置。 \ No newline at end of file diff --git a/site/src/site/sphinx/stack.md b/site/src/site/sphinx/stack.md index b98fd80cf..2fd30c8b2 100644 --- a/site/src/site/sphinx/stack.md +++ b/site/src/site/sphinx/stack.md @@ -31,7 +31,7 @@ stack #### 启动 Demo -启动[快速入门](quick-start.md)里的`arthas-demo`。 +启动[快速入门](quick-start.md)里的`math-game`。 #### stack diff --git a/site/src/site/sphinx/stop.md b/site/src/site/sphinx/stop.md new file mode 100644 index 000000000..488d5f34e --- /dev/null +++ b/site/src/site/sphinx/stop.md @@ -0,0 +1,7 @@ +Stop +=== + +关闭 Arthas 服务端,所有 Arthas 客户端全部退出。 + +> 关闭Arthas服务器之前,会重置掉所有做过的增强类。但是用redefine重加载的类内容不会被重置。 + diff --git a/site/src/site/sphinx/trace.md b/site/src/site/sphinx/trace.md index fd8dda492..84bb7b9f9 100644 --- a/site/src/site/sphinx/trace.md +++ b/site/src/site/sphinx/trace.md @@ -34,19 +34,20 @@ trace ### 注意事项 -`trace` 能方便的帮助你定位和发现因 RT 高而导致的性能问题缺陷,但其每次只能跟踪一级方法的调用链路。 +* `trace` 能方便的帮助你定位和发现因 RT 高而导致的性能问题缺陷,但其每次只能跟踪一级方法的调用链路。 -参考:[Trace命令的实现原理](https://github.com/alibaba/arthas/issues/597) + 参考:[Trace命令的实现原理](https://github.com/alibaba/arthas/issues/597) -3.3.0 版本后,可以使用动态Trace功能,不断增加新的匹配类,参考下面的示例。 +* 3.3.0 版本后,可以使用动态Trace功能,不断增加新的匹配类,参考下面的示例。 +* 目前不支持 `trace java.lang.Thread getName`,参考issue: [#1610](https://github.com/alibaba/arthas/issues/1610) ,考虑到不是非常必要场景,且修复有一定难度,因此当前暂不修复 ### 使用参考 #### 启动 Demo -启动[快速入门](quick-start.md)里的`arthas-demo`。 +启动[快速入门](quick-start.md)里的`math-game`。 #### trace函数 @@ -63,6 +64,8 @@ Affect(class-cnt:1 , method-cnt:1) cost in 28 ms. `---[0.03752ms] demo.MathGame:primeFactors() #24 [throws Exception] ``` +> 结果里的 `#24`,表示在run函数里,在源文件的第`24`行调用了`primeFactors()`函数。 + #### trace次数限制 如果方法调用的次数很多,那么可以用`-n`参数指定捕捉结果的次数。比如下面的例子里,捕捉到一次调用就退出命令。 @@ -145,12 +148,20 @@ trace命令只会trace匹配到的函数里的子调用,并不会向下trace trace -E com.test.ClassA|org.test.ClassB method1|method2|method3 ``` +#### 排除掉指定的类 + +使用 `--exclude-class-pattern` 参数可以排除掉指定的类,比如: + +```bash +trace javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter +``` + ### 动态trace -3.3.0 版本后支持。 +> 3.3.0 版本后支持。 -打开终端1,trace `run`函数,可以看到打印出 `listenerId: 1`: +打开终端1,trace上面demo里的`run`函数,可以看到打印出 `listenerId: 1`: ```bash [arthas@59161]$ trace demo.MathGame run @@ -193,3 +204,41 @@ Affect(class count: 1 , method count: 1) cost in 34 ms, listenerId: 1 ``` 通过指定`listenerId`的方式动态trace,可以不断深入。另外 `watch`/`tt`/`monitor`等命令也支持类似的功能。 + + +### trace结果时间不准确问题 + +比如下面的结果里:`0.705196 > (0.152743 + 0.145825)` + +```bash +$ trace demo.MathGame run -n 1 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 66 ms, listenerId: 1 +`---ts=2021-02-08 11:27:36;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@232204a1 + `---[0.705196ms] demo.MathGame:run() + +---[0.152743ms] demo.MathGame:primeFactors() #24 + `---[0.145825ms] demo.MathGame:print() #25 +``` + +那么其它的时间消耗在哪些地方? + +1. 没有被trace到的函数。比如`java.*` 下的函数调用默认会忽略掉。通过增加`--skipJDKMethod false`参数可以打印出来。 + + ```bash + $ trace demo.MathGame run --skipJDKMethod false + Press Q or Ctrl+C to abort. + Affect(class count: 1 , method count: 1) cost in 35 ms, listenerId: 2 + `---ts=2021-02-08 11:27:48;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@232204a1 + `---[0.810591ms] demo.MathGame:run() + +---[0.034568ms] java.util.Random:nextInt() #23 + +---[0.119367ms] demo.MathGame:primeFactors() #24 [throws Exception] + +---[0.017407ms] java.lang.StringBuilder:() #28 + +---[0.127922ms] java.lang.String:format() #57 + +---[min=0.01419ms,max=0.020221ms,total=0.034411ms,count=2] java.lang.StringBuilder:append() #57 + +---[0.021911ms] java.lang.Exception:getMessage() #57 + +---[0.015643ms] java.lang.StringBuilder:toString() #57 + `---[0.086622ms] java.io.PrintStream:println() #57 + ``` +2. 非函数调用的指令消耗。比如 `i++`, `getfield`等指令。 + +3. 在代码执行过程中,JVM可能出现停顿,比如GC,进入同步块等。 \ No newline at end of file diff --git a/site/src/site/sphinx/tt.md b/site/src/site/sphinx/tt.md index ceff9ff26..bd9472ce2 100644 --- a/site/src/site/sphinx/tt.md +++ b/site/src/site/sphinx/tt.md @@ -16,7 +16,7 @@ tt #### 启动 Demo -启动[快速入门](quick-start.md)里的`arthas-demo`。 +启动[快速入门](quick-start.md)里的`math-game`。 #### 记录调用 @@ -173,7 +173,45 @@ Time fragment[1004] successfully replayed. Affect(row-cnt:1) cost in 14 ms. ``` -你会发现结果虽然一样,但调用的路径发生了变化,有原来的程序发起变成了 Arthas 自己的内部线程发起的调用了。 +你会发现结果虽然一样,但调用的路径发生了变化,由原来的程序发起变成了 Arthas 自己的内部线程发起的调用了。 + + +#### 观察表达式 + +`-w, --watch-express` 观察时空隧道使用`ognl` 表达式 + +* 使用[表达式核心变量](advice-class.md)中所有变量作为已知条件编写表达式。 + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w 'target.illegalArgumentCount' -x 1 -i 1000 +@Integer[60] +Affect(row-cnt:1) cost in 7 ms. +``` + +* 获取类的静态字段、调用类的静态方法 + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w '@demo.MathGame@random.nextInt(100)' -x 1 -i 1000 +@Integer[46] +``` + +注意这里使用 `com.taobao.arthas.core.advisor.Advice#getLoader`加载,使用精确`classloader` [ognl](ognl.md)更好。 + + +高级用法 [获取spring context 调用bean 方法](https://github.com/alibaba/arthas/issues/482) + - 需要强调的点 diff --git a/site/src/site/sphinx/tunnel.md b/site/src/site/sphinx/tunnel.md new file mode 100644 index 000000000..b34f5d258 --- /dev/null +++ b/site/src/site/sphinx/tunnel.md @@ -0,0 +1,119 @@ +Arthas Tunnel +=== + +通过Arthas Tunnel Server/Client 来远程管理/连接多个Agent。 + +比如,在流式计算里,Java进程可以是在不同的机器启动的,想要使用Arthas去诊断会比较麻烦,因为用户通常没有机器的权限,即使登陆机器也分不清是哪个Java进程。 + +在这种情况下,可以使用Arthas Tunnel Server/Client。 + +参考: +* [Web Console](web-console.md) +* [Arthas Spring Boot Starter](spring-boot-starter.md) + +### 下载部署arthas tunnel server + +[https://github.com/alibaba/arthas/releases](https://github.com/alibaba/arthas/releases) + +* 从Maven仓库下载:[![](https://img.shields.io/maven-central/v/com.taobao.arthas/arthas-packaging.svg?style=flat-square "Arthas")](https://arthas.aliyun.com/download/arthas-tunnel-server/latest_version?mirror=aliyun) + +* 从Github Releases页下载: [https://github.com/alibaba/arthas/releases](https://github.com/alibaba/arthas/releases) + + +Arthas tunnel server是一个spring boot fat jar应用,直接`java -jar`启动: + +```bash +java -jar arthas-tunnel-server.jar +``` + +默认情况下,arthas tunnel server的web端口是`8080`,arthas agent连接的端口是`7777`。 + +启动之后,可以访问 [http://127.0.0.1:8080/](http://127.0.0.1:8080/) ,再通过`agentId`连接到已注册的arthas agent上。 + +通过Spring Boot的Endpoint,可以查看到具体的连接信息: [http://127.0.0.1:8080/actuator/arthas](http://127.0.0.1:8080/actuator/arthas) ,登陆用户名是`arthas`,密码在arthas tunnel server的日志里可以找到,比如: + +``` +32851 [main] INFO o.s.b.a.s.s.UserDetailsServiceAutoConfiguration + +Using generated security password: f1dca050-3777-48f4-a577-6367e55a78a2 +``` + +### 启动arthas时连接到tunnel server + +在启动arthas,可以传递`--tunnel-server`参数,比如: + +```bash +as.sh --tunnel-server 'ws://127.0.0.1:7777/ws' +``` + +也可以使用下面的测试地址(不保证一直可用): + +```bash +as.sh --tunnel-server 'ws://47.75.156.201:80/ws' +``` + +* 如果有特殊需求,可以通过`--agent-id`参数里指定agentId。默认情况下,会生成随机ID。 + + +attach成功之后,会打印出agentId,比如: + +```bash + ,---. ,------. ,--------.,--. ,--. ,---. ,---. + / O \ | .--. ''--. .--'| '--' | / O \ ' .-' +| .-. || '--'.' | | | .--. || .-. |`. `-. +| | | || |\ \ | | | | | || | | |.-' | +`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' + + +wiki https://arthas.aliyun.com/doc +tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html +version 3.1.2 +pid 86183 +time 2019-08-30 15:40:53 +id URJZ5L48RPBR2ALI5K4V +``` + +如果是启动时没有连接到 tunnel server,也可以在后续自动重连成功之后,通过 session命令来获取 agentId: + +```bash +[arthas@86183]$ session + Name Value +----------------------------------------------------- + JAVA_PID 86183 + SESSION_ID f7273eb5-e7b0-4a00-bc5b-3fe55d741882 + AGENT_ID URJZ5L48RPBR2ALI5K4V + TUNNEL_SERVER ws://47.75.156.201:80/ws +``` + + +以上面的为例,在浏览器里访问 [http://47.75.156.201/arthas/?port=80](http://47.75.156.201/arthas/?port=80) ,输入 `agentId`,就可以连接到本机上的arthas了。 + + +![](_static/arthas-tunnel-server.png) + + +### 最佳实践 + +> 注意,agentId要保持唯一,否则会在tunnel server上冲突,不能正常工作。 + +如果 arthas agent配置了 `appName`,则生成的agentId会带上`appName`的前缀。 + +比如在加上启动参数:`as.sh --tunnel-server 'ws://127.0.0.1:7777/ws' --app-name demoapp` ,则生成的agentId可能是`demoapp_URJZ5L48RPBR2ALI5K4V`。 + +Tunnel server会以`_`做分隔符,提取出`appName`,方便按应用进行管理。 + +> 另外,也可以在解压的arthas目录下的 `arthas.properties`,或者在spring boot应用的`application.properties`里配置`appName`。 + + +### 集群方式管理 + +如果希望部署多台 tunnel server,可以通过nginx做转发,redis来保存agent信息。 + + +### Arthas tunnel server的工作原理 + +``` +browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent +``` + +[tunnel-server/README.md](https://github.com/alibaba/arthas/blob/master/tunnel-server/README.md#) diff --git a/site/src/site/sphinx/version.md b/site/src/site/sphinx/version.md new file mode 100644 index 000000000..293fa6c6e --- /dev/null +++ b/site/src/site/sphinx/version.md @@ -0,0 +1,12 @@ +version +=== + +输出当前目标 Java 进程所加载的 Arthas 版本号 + +### 使用参考 + +``` +$ version + 3.5.1 +``` + diff --git a/site/src/site/sphinx/vmtool.md b/site/src/site/sphinx/vmtool.md new file mode 100644 index 000000000..59ab1f514 --- /dev/null +++ b/site/src/site/sphinx/vmtool.md @@ -0,0 +1,83 @@ +vmtool +=== + +> @since 3.5.1 + +[`vmtool`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn&id=command-vmtool) + +`vmtool` 利用`JVMTI`接口,实现查询内存对象,强制GC等功能。 + +* [JVM Tool Interface](https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html) + +### 获取对象 + +```bash +$ vmtool --action getInstances --className java.lang.String --limit 10 +@String[][ + @String[com/taobao/arthas/core/shell/session/Session], + @String[com.taobao.arthas.core.shell.session.Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/], + @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], + @String[java/util/concurrent/locks/LockSupport], +] +``` + +> 通过 `--limit`参数,可以限制返回值数量,避免获取超大数据时对JVM造成压力。默认值是10。 + +### 指定 classloader name + +```bash +vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext +``` + + +### 指定 classloader hash + +可以通过`sc`命令查找到加载class的 classloader。 + +```bash +$ sc -d org.springframework.context.ApplicationContext + class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext + code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/ + name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext +... + class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2 + +-sun.misc.Launcher$AppClassLoader@75b84c92 + +-sun.misc.Launcher$ExtClassLoader@4f023edb + classLoaderHash 19469ea2 +``` + +然后用`-c`/`--classloader` 参数指定: + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext +``` + +### 指定返回结果展开层数 + +> `getInstances` action返回结果绑定到`instances`变量上,它是数组。 + +> 通过 `-x`/`--expand` 参数可以指定结果的展开层次,默认值是1。 + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2 +``` + +### 执行表达式 + +> `getInstances` action返回结果绑定到`instances`变量上,它是数组。可以通过`--express`参数执行指定的表达式。 + +```bash +vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext --express 'instances[0].getBeanDefinitionNames()' +``` + +### 强制GC + +```bash +vmtool --action forceGc +``` \ No newline at end of file diff --git a/site/src/site/sphinx/watch.md b/site/src/site/sphinx/watch.md index 81e4b754b..1deb3b132 100644 --- a/site/src/site/sphinx/watch.md +++ b/site/src/site/sphinx/watch.md @@ -42,7 +42,7 @@ watch 的参数比较多,主要是因为它能在 4 个不同的场景观察 #### 启动 Demo -启动[快速入门](quick-start.md)里的`arthas-demo`。 +启动[快速入门](quick-start.md)里的`math-game`。 #### 观察方法出参和返回值 @@ -52,7 +52,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 44 ms. ts=2018-12-03 19:16:51; [cost=1.280502ms] result=@ArrayList[ @Object[][ - @Integer[535629513], + @Integer[1], ], @ArrayList[ @Integer[3], @@ -88,7 +88,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 46 ms. ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -98,7 +98,7 @@ ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ ] ts=2018-12-03 19:29:54; [cost=4.277392ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -131,7 +131,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 58 ms. ts=2018-12-03 19:34:19; [cost=0.587833ms] result=@ArrayList[ @Object[][ - @Integer[47816758], + @Integer[1], ], @MathGame[ random=@Random[ @@ -199,7 +199,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 66 ms. ts=2018-12-03 19:40:28; [cost=2112.168897ms] result=@ArrayList[ @Object[][ - @Integer[2141897465], + @Integer[1], ], @ArrayList[ @Integer[5], @@ -234,3 +234,75 @@ Affect(class-cnt:1 , method-cnt:1) cost in 67 ms. ts=2018-12-03 20:04:34; [cost=131.303498ms] result=@Integer[8] ts=2018-12-03 20:04:35; [cost=0.961441ms] result=@Integer[8] ``` + +#### 获取类的静态字段、调用类的静态方法的例子 + +```bash +watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -v -n 1 -x 2 +[arthas@6527]$ watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -n 1 -x 2 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 5) cost in 34 ms, listenerId: 3 +ts=2021-01-05 21:35:20; [cost=0.173966ms] result=@ArrayList[ + @Object[][ + @Integer[-138282], + ], + @Integer[89], +] +``` + +* 注意这里使用 `Thread.currentThread().getContextClassLoader()` 加载,使用精确`classloader` [ognl](ognl.md)更好。 + +#### 排除掉指定的类 + +> watch/trace/monitor/stack/tt 命令都支持 `--exclude-class-pattern` 参数 + +使用 `--exclude-class-pattern` 参数可以排除掉指定的类,比如: + +```bash +watch javax.servlet.Filter * --exclude-class-pattern com.demo.TestFilter +``` +#### 不匹配子类 + +默认情况下 watch/trace/monitor/stack/tt 命令都会匹配子类。如果想不匹配,可以通过全局参数关掉。 + +```bash +options disable-sub-class true +``` + +#### 使用 -v 参数打印更多信息 + +> watch/trace/monitor/stack/tt 命令都支持 `-v` 参数 + +当命令执行之后,没有输出结果。有两种可能: + +1. 匹配到的函数没有被执行 +2. 条件表达式结果是 false + +但用户区分不出是哪种情况。 + +使用 `-v`选项,则会打印`Condition express`的具体值和执行结果,方便确认。 + +比如: + +``` +$ watch -v -x 2 demo.MathGame print 'params' 'params[0] > 100000' +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 29 ms, listenerId: 11 +Condition express: params[0] > 100000 , result: false +Condition express: params[0] > 100000 , result: false +Condition express: params[0] > 100000 , result: true +ts=2020-12-02 22:38:56; [cost=0.060843ms] result=@Object[][ + @Integer[200033], + @ArrayList[ + @Integer[200033], + ], +] +Condition express: params[0] > 100000 , result: true +ts=2020-12-02 22:38:57; [cost=0.052877ms] result=@Object[][ + @Integer[123047], + @ArrayList[ + @Integer[29], + @Integer[4243], + ], +] +``` \ No newline at end of file diff --git a/site/src/site/sphinx/web-console.md b/site/src/site/sphinx/web-console.md index 9fa0e5cd0..549657409 100644 --- a/site/src/site/sphinx/web-console.md +++ b/site/src/site/sphinx/web-console.md @@ -16,91 +16,7 @@ Arthas目前支持Web Console,用户在attach成功之后,可以直接访问 > 默认情况下,arthas只listen 127.0.0.1,所以如果想从远程连接,则可以使用 `--target-ip`参数指定listen的IP,更多参考`-h`的帮助说明。 > 注意会有安全风险,考虑下面的tunnel server的方案。 -后续更多Web Console功能支持,请到issue下留言:[https://github.com/alibaba/arthas/issues/15](https://github.com/alibaba/arthas/issues/15) - - +* 在Web Console复制粘贴快捷键参考: [https://github.com/alibaba/arthas/issues/1056](https://github.com/alibaba/arthas/issues/1056) ### 使用arthas tunnel server连接远程arthas - -#### 下载部署arthas tunnel server - -[https://github.com/alibaba/arthas/releases](https://github.com/alibaba/arthas/releases) - -Arthas tunnel server是一个spring boot fat jar应用,直接`java -jar`启动: - -```bash -java -jar arthas-tunnel-server.jar -``` - -默认情况下,arthas tunnel server的web端口是`8080`,arthas agent连接的端口是`7777`。 - -启动之后,可以访问 [http://127.0.0.1:8080/](http://127.0.0.1:8080/) ,再通过`agentId`连接到已注册的arthas agent上。 - -通过Spring Boot的Endpoint,可以查看到具体的连接信息: [http://127.0.0.1:8080/actuator/arthas](http://127.0.0.1:8080/actuator/arthas) ,登陆用户名是`arthas`,密码在arthas tunnel server的日志里可以找到,比如: - -``` -32851 [main] INFO o.s.b.a.s.s.UserDetailsServiceAutoConfiguration - -Using generated security password: f1dca050-3777-48f4-a577-6367e55a78a2 -``` - -#### 启动arthas时连接到tunnel server - -在启动arthas,可以传递`--tunnel-server`参数,比如: - -```bash -as.sh --tunnel-server 'ws://127.0.0.1:7777/ws' -``` - -也可以使用下面的测试地址(不保证一直可用): - -```bash -as.sh --tunnel-server 'ws://47.75.156.201:7777/ws' -``` - -* 如果有特殊需求,可以通过`--agent-id`参数里指定agentId。默认情况下,会生成随机ID。 - -attach成功之后,会打印出agentId,比如: - -```bash - ,---. ,------. ,--------.,--. ,--. ,---. ,---. - / O \ | .--. ''--. .--'| '--' | / O \ ' .-' -| .-. || '--'.' | | | .--. || .-. |`. `-. -| | | || |\ \ | | | | | || | | |.-' | -`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' - - -wiki https://arthas.aliyun.com/doc -tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html -version 3.1.2 -pid 86183 -time 2019-08-30 15:40:53 -id URJZ5L48RPBR2ALI5K4V -``` - -如果是启动时没有连接到 tunnel server,也可以在后续自动重连成功之后,通过 session命令来获取 agentId: - -```bash -[arthas@86183]$ session - Name Value ------------------------------------------------------ - JAVA_PID 86183 - SESSION_ID f7273eb5-e7b0-4a00-bc5b-3fe55d741882 - AGENT_ID URJZ5L48RPBR2ALI5K4V - TUNNEL_SERVER ws://47.75.156.201:7777/ws -``` - - -以上面的为例,在浏览器里访问 [http://47.75.156.201:8080/](http://47.75.156.201:8080/) ,输入 `agentId`,就可以连接到本机上的arthas了。 - - -![](_static/arthas-tunnel-server.png) - - -#### Arthas tunnel server的工作原理 - -``` -browser <-> arthas tunnel server <-> arthas tunnel client <-> arthas agent -``` - -[tunnel-server/README.md](https://github.com/alibaba/arthas/blob/master/tunnel-server/README.md#) \ No newline at end of file +[Arthas Tunnel](tunnel.md) \ No newline at end of file diff --git a/spy/pom.xml b/spy/pom.xml index 80fa17f6a..b0ff9b411 100644 --- a/spy/pom.xml +++ b/spy/pom.xml @@ -1,15 +1,25 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-spy arthas-spy + + + com.taobao.arthas + arthas-common + ${project.version} + provided + true + + + arthas-spy diff --git a/static/cvte.png b/static/cvte.png new file mode 100644 index 000000000..eec8451a7 Binary files /dev/null and b/static/cvte.png differ diff --git a/static/qdm_logo.png b/static/qdm_logo.png new file mode 100644 index 000000000..7c0e9dc3b Binary files /dev/null and b/static/qdm_logo.png differ diff --git a/static/youzan.png b/static/youzan.png new file mode 100644 index 000000000..29fb96c78 Binary files /dev/null and b/static/youzan.png differ diff --git a/static/zhongyuanbank.png b/static/zhongyuanbank.png new file mode 100644 index 000000000..e7730cbe4 Binary files /dev/null and b/static/zhongyuanbank.png differ diff --git a/testcase/pom.xml b/testcase/pom.xml index ed0e033e7..cede6748d 100644 --- a/testcase/pom.xml +++ b/testcase/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-testcase diff --git a/tunnel-client/pom.xml b/tunnel-client/pom.xml index 5d1480cab..f66a69a92 100644 --- a/tunnel-client/pom.xml +++ b/tunnel-client/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-tunnel-client @@ -16,6 +16,11 @@ arthas-common ${project.version} + + com.taobao.arthas + arthas-tunnel-common + ${project.version} + org.slf4j diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClient.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClient.java index 89eaa22ae..0e671a259 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClient.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClient.java @@ -8,6 +8,8 @@ import javax.net.ssl.SSLException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.taobao.arthas.common.ArthasConstants; + import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -91,7 +93,7 @@ public class ForwardClient { if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc(), host, port)); } - p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), websocketClientHandler, + p.addLast(new HttpClientCodec(), new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH), websocketClientHandler, forwardClientSocketClientHandler); } }); diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java index ca488a2ce..b1267fd2a 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ForwardClientSocketClientHandler.java @@ -84,7 +84,7 @@ public class ForwardClientSocketClientHandler extends SimpleChannelInboundHandle @Override protected void initChannel(LocalChannel ch) { ChannelPipeline p = ch.pipeline(); - p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), websocketClientHandler, + p.addLast(new HttpClientCodec(), new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH), websocketClientHandler, localFrameHandler); } }); diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/LocalFrameHandler.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/LocalFrameHandler.java index bcae1127e..2f06ff361 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/LocalFrameHandler.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/LocalFrameHandler.java @@ -1,5 +1,8 @@ package com.alibaba.arthas.tunnel.client; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; import io.netty.channel.SimpleChannelInboundHandler; @@ -7,7 +10,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.Cli import io.netty.handler.codec.http.websocketx.WebSocketFrame; public class LocalFrameHandler extends SimpleChannelInboundHandler { - + private final static Logger logger = LoggerFactory.getLogger(LocalFrameHandler.class); private ChannelPromise handshakeFuture; public LocalFrameHandler() { @@ -34,7 +37,7 @@ public class LocalFrameHandler extends SimpleChannelInboundHandler httpResponsePromise = GlobalEventExecutor.INSTANCE.newPromise(); + + final EventLoopGroup group = new NioEventLoopGroup(1, new DefaultThreadFactory("arthas-ProxyClient", true)); + ChannelFuture closeFuture = null; + try { + Bootstrap b = new Bootstrap(); + b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000); + b.group(group).channel(LocalChannel.class).handler(new ChannelInitializer() { + @Override + protected void initChannel(LocalChannel ch) { + ChannelPipeline p = ch.pipeline(); + p.addLast(new HttpClientCodec(), new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH), + new HttpProxyClientHandler(httpResponsePromise)); + } + }); + + LocalAddress localAddress = new LocalAddress(ArthasConstants.NETTY_LOCAL_ADDRESS); + Channel localChannel = b.connect(localAddress).sync().channel(); + + // Prepare the HTTP request. + HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, targetUrl, + Unpooled.EMPTY_BUFFER); + request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); + + localChannel.writeAndFlush(request); + + closeFuture = localChannel.closeFuture(); + logger.info("proxy client connect to server success, targetUrl: " + targetUrl); + + return httpResponsePromise.get(5000, TimeUnit.MILLISECONDS); + } catch (Throwable e) { + logger.error("ProxyClient error, targetUrl: {}", targetUrl, e); + } finally { + if (closeFuture != null) { + closeFuture.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + group.shutdownGracefully(); + } + }); + } else { + group.shutdownGracefully(); + } + } + + SimpleHttpResponse httpResponse = new SimpleHttpResponse(); + try { + httpResponse.setContent(new String("error").getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + // ignore + } + return httpResponse; + } + + class HttpProxyClientHandler extends SimpleChannelInboundHandler { + + private Promise promise; + + private SimpleHttpResponse simpleHttpResponse = new SimpleHttpResponse(); + + public HttpProxyClientHandler(Promise promise) { + this.promise = promise; + } + + @Override + public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) { + if (msg instanceof HttpResponse) { + HttpResponse response = (HttpResponse) msg; + + simpleHttpResponse.setStatus(response.status().code()); + if (!response.headers().isEmpty()) { + for (String name : response.headers().names()) { + for (String value : response.headers().getAll(name)) { + if (logger.isDebugEnabled()) { + logger.debug("header: {}, value: {}", name, value); + } + + simpleHttpResponse.addHeader(name, value); + } + } + } + } + if (msg instanceof HttpContent) { + HttpContent content = (HttpContent) msg; + + ByteBuf byteBuf = content.content(); + byte[] bytes = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(bytes); + + simpleHttpResponse.setContent(bytes); + + promise.setSuccess(simpleHttpResponse); + + if (content instanceof LastHttpContent) { + ctx.close(); + } + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + logger.error("Proxy Client error", cause); + ctx.close(); + } + } +} diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/RelayHandler.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/RelayHandler.java index 9f7988fcc..234b0f24d 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/RelayHandler.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/RelayHandler.java @@ -1,5 +1,8 @@ package com.alibaba.arthas.tunnel.client; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; @@ -7,7 +10,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.util.ReferenceCountUtil; public final class RelayHandler extends ChannelInboundHandlerAdapter { - + private final static Logger logger = LoggerFactory.getLogger(RelayHandler.class); private final Channel relayChannel; public RelayHandler(Channel relayChannel) { @@ -37,7 +40,7 @@ public final class RelayHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { - cause.printStackTrace(); + logger.error("RelayHandler error", cause); ctx.close(); } } diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClient.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClient.java index e6b22636f..f79a067e7 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClient.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClient.java @@ -9,6 +9,10 @@ import javax.net.ssl.SSLException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.alibaba.arthas.tunnel.common.MethodConstants; +import com.alibaba.arthas.tunnel.common.URIConstans; +import com.taobao.arthas.common.ArthasConstants; + import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; @@ -30,6 +34,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; +import io.netty.handler.timeout.IdleStateHandler; import io.netty.util.concurrent.DefaultThreadFactory; /** @@ -48,18 +53,30 @@ public class TunnelClient { // two thread because need to reconnect. #1284 private EventLoopGroup eventLoopGroup = new NioEventLoopGroup(2, new DefaultThreadFactory("arthas-TunnelClient", true)); + private String appName; // agent id, generated by tunnel server. if reconnect, reuse the id volatile private String id; + /** + * arthas version + */ + private String version = "unknown"; + + private volatile boolean connected = false; + public ChannelFuture start() throws IOException, InterruptedException, URISyntaxException { return connect(false); } public ChannelFuture connect(boolean reconnect) throws SSLException, URISyntaxException, InterruptedException { QueryStringEncoder queryEncoder = new QueryStringEncoder(this.tunnelServerUrl); - queryEncoder.addParam("method", "agentRegister"); + queryEncoder.addParam(URIConstans.METHOD, MethodConstants.AGENT_REGISTER); + queryEncoder.addParam(URIConstans.ARTHAS_VERSION, this.version); + if (appName != null) { + queryEncoder.addParam(URIConstans.APP_NAME, appName); + } if (id != null) { - queryEncoder.addParam("id", id); + queryEncoder.addParam(URIConstans.ID, id); } // ws://127.0.0.1:7777/ws?method=agentRegister final URI agentRegisterURI = queryEncoder.toUri(); @@ -112,7 +129,8 @@ public class TunnelClient { p.addLast(sslCtx.newHandler(ch.alloc(), host, port)); } - p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), websocketClientHandler, + p.addLast(new HttpClientCodec(), new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH), websocketClientHandler, + new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS), handler); } }); @@ -161,4 +179,27 @@ public class TunnelClient { this.id = id; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public boolean isConnected() { + return connected; + } + + public void setConnected(boolean connected) { + this.connected = connected; + } } diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java index 11179ac0f..875de6e4d 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java @@ -2,26 +2,31 @@ package com.alibaba.arthas.tunnel.client; import java.net.URI; -import java.net.URL; import java.util.List; import java.util.Map; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.alibaba.arthas.tunnel.common.MethodConstants; +import com.alibaba.arthas.tunnel.common.SimpleHttpResponse; +import com.alibaba.arthas.tunnel.common.URIConstans; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; -import io.netty.channel.EventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.handler.codec.base64.Base64; import io.netty.handler.codec.http.QueryStringDecoder; import io.netty.handler.codec.http.QueryStringEncoder; +import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.util.concurrent.DefaultThreadFactory; +import io.netty.handler.timeout.IdleStateEvent; +import io.netty.util.CharsetUtil; /** * @@ -57,25 +62,26 @@ public class TunnelClientSocketClientHandler extends SimpleChannelInboundHandler QueryStringDecoder queryDecoder = new QueryStringDecoder(text); Map> parameters = queryDecoder.parameters(); - List methodList = parameters.get("method"); + List methodList = parameters.get(URIConstans.METHOD); String method = null; if (methodList != null && !methodList.isEmpty()) { method = methodList.get(0); } - if ("agentRegister".equals(method)) { - List idList = parameters.get("id"); + if (MethodConstants.AGENT_REGISTER.equals(method)) { + List idList = parameters.get(URIConstans.ID); if (idList != null && !idList.isEmpty()) { this.tunnelClient.setId(idList.get(0)); } + tunnelClient.setConnected(true); registerPromise.setSuccess(); } - if ("startTunnel".equals(method)) { + if (MethodConstants.START_TUNNEL.equals(method)) { QueryStringEncoder queryEncoder = new QueryStringEncoder(this.tunnelClient.getTunnelServerUrl()); - queryEncoder.addParam("method", "openTunnel"); - queryEncoder.addParam("clientConnectionId", parameters.get("clientConnectionId").get(0)); - queryEncoder.addParam("id", parameters.get("id").get(0)); + queryEncoder.addParam(URIConstans.METHOD, MethodConstants.OPEN_TUNNEL); + queryEncoder.addParam(URIConstans.CLIENT_CONNECTION_ID, parameters.get(URIConstans.CLIENT_CONNECTION_ID).get(0)); + queryEncoder.addParam(URIConstans.ID, parameters.get(URIConstans.ID).get(0)); final URI forwardUri = queryEncoder.toUri(); @@ -88,11 +94,52 @@ public class TunnelClientSocketClientHandler extends SimpleChannelInboundHandler } } + if (MethodConstants.HTTP_PROXY.equals(method)) { + /** + *

+                 * 1. 从proxy请求里读取到目标的 targetUrl,和 requestId
+                 * 2. 然后通过 ProxyClient直接请求得到结果
+                 * 3. 把response结果转为 byte[],再转为base64,再统一组合的一个url,再用 TextWebSocketFrame 发回去
+                 * 
+ * + */ + ProxyClient proxyClient = new ProxyClient(); + List targetUrls = parameters.get(URIConstans.TARGET_URL); + + List requestIDs = parameters.get(URIConstans.PROXY_REQUEST_ID); + String id = null; + if (requestIDs != null && !requestIDs.isEmpty()) { + id = requestIDs.get(0); + } + if (id == null) { + logger.error("error, http proxy need {}", URIConstans.PROXY_REQUEST_ID); + return; + } + + if (targetUrls != null && !targetUrls.isEmpty()) { + String targetUrl = targetUrls.get(0); + SimpleHttpResponse simpleHttpResponse = proxyClient.query(targetUrl); + + ByteBuf byteBuf = Base64 + .encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse))); + String requestData = byteBuf.toString(CharsetUtil.UTF_8); + + QueryStringEncoder queryEncoder = new QueryStringEncoder(""); + queryEncoder.addParam(URIConstans.METHOD, MethodConstants.HTTP_PROXY); + queryEncoder.addParam(URIConstans.PROXY_REQUEST_ID, id); + queryEncoder.addParam(URIConstans.PROXY_RESPONSE_DATA, requestData); + + String url = queryEncoder.toString(); + ctx.writeAndFlush(new TextWebSocketFrame(url)); + } + } + } } @Override public void channelUnregistered(final ChannelHandlerContext ctx) throws Exception { + tunnelClient.setConnected(false); ctx.channel().eventLoop().schedule(new Runnable() { @Override public void run() { @@ -106,11 +153,21 @@ public class TunnelClientSocketClientHandler extends SimpleChannelInboundHandler }, tunnelClient.getReconnectDelay(), TimeUnit.SECONDS); } + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if (evt instanceof IdleStateEvent) { + ctx.writeAndFlush(new PingWebSocketFrame()); + } else { + super.userEventTriggered(ctx, evt); + } + } + @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + logger.error("TunnelClient error, tunnel server url: " + tunnelClient.getTunnelServerUrl(), cause); if (!registerPromise.isDone()) { registerPromise.setFailure(cause); } - ctx.fireExceptionCaught(cause); + ctx.close(); } } diff --git a/tunnel-common/pom.xml b/tunnel-common/pom.xml new file mode 100644 index 000000000..6258e4a89 --- /dev/null +++ b/tunnel-common/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + com.taobao.arthas + arthas-all + ${revision} + ../pom.xml + + arthas-tunnel-common + arthas-tunnel-common + + + + + + + + arthas-tunnel-common + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + UTF-8 + true + + + + + + diff --git a/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/MethodConstants.java b/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/MethodConstants.java new file mode 100644 index 000000000..9c97636fc --- /dev/null +++ b/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/MethodConstants.java @@ -0,0 +1,60 @@ +package com.alibaba.arthas.tunnel.common; + +/** + * tunnel client和server之间通过 URI来通迅,在URI里定义了一个 method的参数,定义不同的行为 + * + * @author hengyunabc 2020-10-22 + * + */ +public class MethodConstants { + + /** + * + *
+     * tunnel client启动时注册的 method
+     * 
+     * ws://192.168.1.10:7777/ws?method=agentRegister
+     * 
+     * tunnel server回应:
+     * 
+     * response:/?method=agentRegister&id=bvDOe8XbTM2pQWjF4cfw
+     * 
+     * id不指定,则随机生成
+     * 
+ */ + public static final String AGENT_REGISTER = "agentRegister"; + + /** + *
+     * tunnel server 通知 tunnel client启动一个新的连接
+     * 
+     * response:/?method=startTunnel&id=bvDOe8XbTM2pQWjF4cfw&clientConnectionId=AMku9EFz2gxeL2gedGOC
+     * 
+ */ + public static final String START_TUNNEL = "startTunnel"; + /** + *
+     * browser 通知tunnel server去连接 tunnel client
+     * 
+     * ws://192.168.1.10:7777/ws?method=connectArthas&id=bvDOe8XbTM2pQWjF4cfw
+     * 
+ */ + public static final String CONNECT_ARTHAS = "connectArthas"; + + /** + *
+     * tunnel client收到 startTunnel 指令之后,以下面的 URI新建一个连接:
+     * 
+     * ws://127.0.0.1:7777/ws/?method=openTunnel&clientConnectionId=AMku9EFz2gxeL2gedGOC&id=bvDOe8XbTM2pQWjF4cfw
+     * 
+ */ + public static final String OPEN_TUNNEL = "openTunnel"; + + /** + *
+     * tunnel server向 tunnel client请求 http中转,比如访问 http://localhost:3658/arthas-output/xxx.svg
+     * 
+ */ + public static final String HTTP_PROXY = "httpProxy"; + +} diff --git a/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/SimpleHttpResponse.java b/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/SimpleHttpResponse.java new file mode 100644 index 000000000..bdaacc20c --- /dev/null +++ b/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/SimpleHttpResponse.java @@ -0,0 +1,89 @@ +package com.alibaba.arthas.tunnel.common; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author hengyunabc 2020-10-22 + * + */ +public class SimpleHttpResponse implements Serializable { + + private static final long serialVersionUID = 1L; + + private int status = 200; + + private Map headers = new HashMap(); + + private byte[] content; + + public void addHeader(String key, String value) { + headers.put(key, value); + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public byte[] getContent() { + return content; + } + + public void setContent(byte[] content) { + this.content = content; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public static byte[] toBytes(SimpleHttpResponse response) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream out = null; + try { + out = new ObjectOutputStream(bos); + out.writeObject(response); + out.flush(); + return bos.toByteArray(); + } finally { + try { + bos.close(); + } catch (IOException ex) { + // ignore close exception + } + } + } + + public static SimpleHttpResponse fromBytes(byte[] bytes) throws IOException, ClassNotFoundException { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInput in = null; + try { + in = new ObjectInputStream(bis); + return (SimpleHttpResponse) in.readObject(); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException ex) { + // ignore close exception + } + } + } +} diff --git a/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/URIConstans.java b/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/URIConstans.java new file mode 100644 index 000000000..2dcded068 --- /dev/null +++ b/tunnel-common/src/main/java/com/alibaba/arthas/tunnel/common/URIConstans.java @@ -0,0 +1,46 @@ +package com.alibaba.arthas.tunnel.common; + +/** + * + * @author hengyunabc 2020-10-22 + * + */ +public class URIConstans { + + /** + * @see MethodConstants + */ + public static final String METHOD = "method"; + public static final String RESPONSE = "response"; + + /** + * agent id + */ + public static final String ID = "id"; + + /** + * tunnel server用于区分不同 tunnel client的内部 id + */ + public static final String CLIENT_CONNECTION_ID = "clientConnectionId"; + + /** + * tunnel server向 tunnel client请求http代理时的目标 url + * + * @see com.alibaba.arthas.tunnel.common.MethodConstants#HTTP_PROXY + */ + public static final String TARGET_URL = "targetUrl"; + + /** + * 标识一次proxy请求,随机生成 + */ + public static final String PROXY_REQUEST_ID = "requestId"; + + /** + * proxy请求的返回值,base64编码 + */ + public static final String PROXY_RESPONSE_DATA = "responseData"; + + public static final String ARTHAS_VERSION = "arthasVersion"; + + public static final String APP_NAME = "appName"; +} diff --git a/tunnel-server/pom.xml b/tunnel-server/pom.xml index ca7542f74..563fa41f1 100644 --- a/tunnel-server/pom.xml +++ b/tunnel-server/pom.xml @@ -1,10 +1,10 @@ - + 4.0.0 com.taobao.arthas arthas-all - 3.4.4-SNAPSHOT + ${revision} ../pom.xml arthas-tunnel-server @@ -32,6 +32,16 @@ + + com.taobao.arthas + arthas-common + ${project.version} + + + com.taobao.arthas + arthas-tunnel-common + ${project.version} + org.springframework.boot spring-boot-starter-webflux @@ -45,6 +55,15 @@ spring-boot-starter-actuator + + org.springframework.boot + spring-boot-starter-data-redis + + + com.github.ben-manes.caffeine + caffeine + + org.springframework.boot spring-boot-starter-security @@ -55,11 +74,39 @@ commons-lang3 + + it.ozimov + embedded-redis + 0.7.3 + + + org.slf4j + slf4j-simple + + + + + + junit + junit + test + + + org.assertj + assertj-core + test + org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + io.projectreactor @@ -84,16 +131,37 @@ + + org.apache.maven.plugins + maven-jar-plugin + + + + jar + + package + + fatjar + + + + org.springframework.boot spring-boot-maven-plugin - 2.1.7.RELEASE + ${spring-boot.version} + + true + - package + repackage repackage + + fatjar + diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentClusterInfo.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentClusterInfo.java new file mode 100644 index 000000000..0efeac84a --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentClusterInfo.java @@ -0,0 +1,63 @@ +package com.alibaba.arthas.tunnel.server; + +/** + * @author hengyunabc 2020-10-30 + * + */ +public class AgentClusterInfo { + /** + * agent本身以哪个ip连接到 tunnel server + */ + private String host; + private int port; + private String arthasVersion; + + /** + * agent 连接到的 tunnel server 的ip + */ + private String clientConnectHost; + + public AgentClusterInfo() { + + } + + public AgentClusterInfo(AgentInfo agentInfo, String clientConnectHost) { + this.host = agentInfo.getHost(); + this.port = agentInfo.getPort(); + this.arthasVersion = agentInfo.getArthasVersion(); + this.clientConnectHost = clientConnectHost; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getArthasVersion() { + return arthasVersion; + } + + public void setArthasVersion(String arthasVersion) { + this.arthasVersion = arthasVersion; + } + + public String getClientConnectHost() { + return clientConnectHost; + } + + public void setClientConnectHost(String clientConnectHost) { + this.clientConnectHost = clientConnectHost; + } + +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentInfo.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentInfo.java index fc11f282d..73459f084 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentInfo.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/AgentInfo.java @@ -15,6 +15,7 @@ public class AgentInfo { private ChannelHandlerContext channelHandlerContext; private String host; private int port; + private String arthasVersion; public ChannelHandlerContext getChannelHandlerContext() { return channelHandlerContext; @@ -40,4 +41,12 @@ public class AgentInfo { this.port = port; } + public String getArthasVersion() { + return arthasVersion; + } + + public void setArthasVersion(String arthasVersion) { + this.arthasVersion = arthasVersion; + } + } diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelServer.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelServer.java index 69396a844..ffe3dc72c 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelServer.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelServer.java @@ -1,6 +1,7 @@ package com.alibaba.arthas.tunnel.server; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -9,6 +10,10 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.alibaba.arthas.tunnel.common.SimpleHttpResponse; +import com.alibaba.arthas.tunnel.server.cluster.TunnelClusterStore; +import com.taobao.arthas.common.ArthasConstants; + import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; @@ -20,6 +25,7 @@ import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.util.concurrent.DefaultThreadFactory; +import io.netty.util.concurrent.Promise; /** * @@ -32,16 +38,32 @@ public class TunnelServer { private boolean ssl; private String host; private int port; + private String path = ArthasConstants.DEFAULT_WEBSOCKET_PATH; private Map agentInfoMap = new ConcurrentHashMap(); private Map clientConnectionInfoMap = new ConcurrentHashMap(); + + /** + * 记录 proxy request + */ + private Map> proxyRequestPromiseMap = new ConcurrentHashMap>(); private EventLoopGroup bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("arthas-TunnelServer-boss", true)); private EventLoopGroup workerGroup = new NioEventLoopGroup(new DefaultThreadFactory("arthas-TunnelServer-worker", true)); private Channel channel; + /** + * 在集群部署时,保存agentId和host关系 + */ + private TunnelClusterStore tunnelClusterStore; + + /** + * 集群部署时外部连接的host + */ + private String clientConnectHost; + public void start() throws Exception { // Configure SSL. final SslContext sslCtx; @@ -70,6 +92,17 @@ public class TunnelServer { agentInfoMap.entrySet().removeIf(e -> !e.getValue().getChannelHandlerContext().channel().isActive()); clientConnectionInfoMap.entrySet() .removeIf(e -> !e.getValue().getChannelHandlerContext().channel().isActive()); + + // 更新集群key信息 + if (tunnelClusterStore != null && clientConnectHost != null) { + try { + for (Entry entry : agentInfoMap.entrySet()) { + tunnelClusterStore.addAgent(entry.getKey(), new AgentClusterInfo(entry.getValue(), clientConnectHost), 60 * 60, TimeUnit.SECONDS); + } + } catch (Throwable t) { + logger.error("update tunnel info error", t); + } + } } }, 60, 60, TimeUnit.SECONDS); @@ -89,12 +122,19 @@ public class TunnelServer { public void addAgent(String id, AgentInfo agentInfo) { agentInfoMap.put(id, agentInfo); + if (this.tunnelClusterStore != null) { + this.tunnelClusterStore.addAgent(id, new AgentClusterInfo(agentInfo, clientConnectHost), 60 * 60, TimeUnit.SECONDS); + } } public AgentInfo removeAgent(String id) { - return agentInfoMap.remove(id); + AgentInfo agentInfo = agentInfoMap.remove(id); + if (this.tunnelClusterStore != null) { + this.tunnelClusterStore.removeAgent(id); + } + return agentInfo; } - + public Optional findClientConnection(String id) { return Optional.ofNullable(this.clientConnectionInfoMap.get(id)); } @@ -106,6 +146,27 @@ public class TunnelServer { public ClientConnectionInfo removeClientConnectionInfo(String id) { return this.clientConnectionInfoMap.remove(id); } + + public void addProxyRequestPromise(String requestId, Promise promise) { + this.proxyRequestPromiseMap.put(requestId, promise); + // 把过期的proxy 请求删掉 + workerGroup.schedule(new Runnable() { + + @Override + public void run() { + removeProxyRequestPromise(requestId); + } + + }, 60, TimeUnit.SECONDS); + } + + public void removeProxyRequestPromise(String requestId) { + this.proxyRequestPromiseMap.remove(requestId); + } + + public Promise findProxyRequestPromise(String requestId) { + return this.proxyRequestPromiseMap.get(requestId); + } public boolean isSsl() { return ssl; @@ -146,4 +207,33 @@ public class TunnelServer { public void setClientConnectionInfoMap(Map clientConnectionInfoMap) { this.clientConnectionInfoMap = clientConnectionInfoMap; } + + public TunnelClusterStore getTunnelClusterStore() { + return tunnelClusterStore; + } + + public void setTunnelClusterStore(TunnelClusterStore tunnelClusterStore) { + this.tunnelClusterStore = tunnelClusterStore; + } + + public String getClientConnectHost() { + return clientConnectHost; + } + + public void setClientConnectHost(String clientConnectHost) { + this.clientConnectHost = clientConnectHost; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + path = path.trim(); + if (!path.startsWith("/")) { + logger.warn("tunnel server path should start with / ! path: {}, try to auto add / .", path); + path = "/" + path; + } + this.path = path; + } } diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketFrameHandler.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketFrameHandler.java index d925a4a2e..73e3f3099 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketFrameHandler.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketFrameHandler.java @@ -5,22 +5,31 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URI; import java.net.URISyntaxException; +import java.net.URLDecoder; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.tomcat.util.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.MultiValueMap; import org.springframework.web.util.UriComponentsBuilder; +import com.alibaba.arthas.tunnel.common.MethodConstants; +import com.alibaba.arthas.tunnel.common.SimpleHttpResponse; +import com.alibaba.arthas.tunnel.common.URIConstans; +import com.alibaba.arthas.tunnel.server.utils.HttpUtils; + import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler.HandshakeComplete; @@ -54,15 +63,15 @@ public class TunnelSocketFrameHandler extends SimpleChannelInboundHandler parameters = UriComponentsBuilder.fromUriString(uri).build().getQueryParams(); - String method = parameters.getFirst("method"); + String method = parameters.getFirst(URIConstans.METHOD); - if ("connectArthas".equals(method)) { // form browser + if (MethodConstants.CONNECT_ARTHAS.equals(method)) { // form browser connectArthas(ctx, parameters); - } else if ("agentRegister".equals(method)) { // form arthas agent, register - agentRegister(ctx, uri); + } else if (MethodConstants.AGENT_REGISTER.equals(method)) { // form arthas agent, register + agentRegister(ctx, handshake, uri); } - if ("openTunnel".equals(method)) { // from arthas agent open tunnel - String clientConnectionId = parameters.getFirst("clientConnectionId"); + if (MethodConstants.OPEN_TUNNEL.equals(method)) { // from arthas agent open tunnel + String clientConnectionId = parameters.getFirst(URIConstans.CLIENT_CONNECTION_ID); openTunnel(ctx, clientConnectionId); } } else { @@ -72,7 +81,41 @@ public class TunnelSocketFrameHandler extends SimpleChannelInboundHandler parameters = UriComponentsBuilder.fromUriString(text).build() + .getQueryParams(); + + String method = parameters.getFirst(URIConstans.METHOD); + + /** + *
+             * 1. 之前http proxy请求已发送到 tunnel cleint,这里接收到 tunnel client的结果,并解析出SimpleHttpResponse
+             * 2. 需要据 URIConstans.PROXY_REQUEST_ID 取出当时的 Promise,再设置SimpleHttpResponse进去
+             * 
+ */ + if (MethodConstants.HTTP_PROXY.equals(method)) { + String requestId = URLDecoder.decode(parameters.getFirst(URIConstans.PROXY_REQUEST_ID), "utf-8"); + + if (requestId == null) { + logger.error("error, need {}, text: {}", URIConstans.PROXY_REQUEST_ID, text); + return; + } + logger.info("received http proxy response, requestId: {}", requestId); + + Promise promise = tunnelServer.findProxyRequestPromise(requestId); + + String data = URLDecoder.decode(parameters.getFirst(URIConstans.PROXY_RESPONSE_DATA), "utf-8"); + + byte[] bytes = Base64.decodeBase64(data); + SimpleHttpResponse simpleHttpResponse = SimpleHttpResponse.fromBytes(bytes); + promise.setSuccess(simpleHttpResponse); + } + } } private void connectArthas(ChannelHandlerContext tunnelSocketCtx, MultiValueMap parameters) @@ -81,7 +124,7 @@ public class TunnelSocketFrameHandler extends SimpleChannelInboundHandler agentId = parameters.getOrDefault("id", Collections.emptyList()); if (agentId.isEmpty()) { - logger.error("arthas agent id can not be null, parameters: ", parameters); + logger.error("arthas agent id can not be null, parameters: {}", parameters); throw new IllegalArgumentException("arthas agent id can not be null"); } @@ -95,8 +138,11 @@ public class TunnelSocketFrameHandler extends SimpleChannelInboundHandler idList = queryDecoder.parameters().get("id"); + Map> parameters = queryDecoder.parameters(); + + String appName = null; + List appNameList = parameters.get(URIConstans.APP_NAME); + if (appNameList != null && !appNameList.isEmpty()) { + appName = appNameList.get(0); + } + + // generate a random agent id + String id = null; + if (appName != null) { + // 如果有传 app name,则生成带 app name前缀的id,方便管理 + id = appName + "_" + RandomStringUtils.random(20, true, true).toUpperCase(); + } else { + id = RandomStringUtils.random(20, true, true).toUpperCase(); + } + // agent传过来,则优先用 agent的 + List idList = parameters.get(URIConstans.ID); if (idList != null && !idList.isEmpty()) { id = idList.get(0); } + String arthasVersion = null; + List arthasVersionList = parameters.get(URIConstans.ARTHAS_VERSION); + if (arthasVersionList != null && !arthasVersionList.isEmpty()) { + arthasVersion = arthasVersionList.get(0); + } + final String finalId = id; - URI responseUri = new URI("response", null, "/", "method=agentRegister" + "&id=" + id, null); + // URI responseUri = new URI("response", null, "/", "method=" + MethodConstants.AGENT_REGISTER + "&id=" + id, null); + URI responseUri = UriComponentsBuilder.newInstance().scheme(URIConstans.RESPONSE).path("/") + .queryParam(URIConstans.METHOD, MethodConstants.AGENT_REGISTER).queryParam(URIConstans.ID, id).build() + .encode().toUri(); AgentInfo info = new AgentInfo(); - SocketAddress remoteAddress = ctx.channel().remoteAddress(); - if (remoteAddress instanceof InetSocketAddress) { - InetSocketAddress inetSocketAddress = (InetSocketAddress) remoteAddress; - info.setHost(inetSocketAddress.getHostString()); - info.setPort(inetSocketAddress.getPort()); + + // 前面可能有nginx代理 + HttpHeaders headers = handshake.requestHeaders(); + String host = HttpUtils.findClientIP(headers); + + if (host == null) { + SocketAddress remoteAddress = ctx.channel().remoteAddress(); + if (remoteAddress instanceof InetSocketAddress) { + InetSocketAddress inetSocketAddress = (InetSocketAddress) remoteAddress; + info.setHost(inetSocketAddress.getHostString()); + info.setPort(inetSocketAddress.getPort()); + } + } else { + info.setHost(host); + Integer port = HttpUtils.findClientPort(headers); + if (port != null) { + info.setPort(port); + } } + info.setChannelHandlerContext(ctx); + if (arthasVersion != null) { + info.setArthasVersion(arthasVersion); + } tunnelServer.addAgent(id, info); ctx.channel().closeFuture().addListener(new GenericFutureListener>() { diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketServerInitializer.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketServerInitializer.java index 5c07f9af2..f69626bed 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketServerInitializer.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/TunnelSocketServerInitializer.java @@ -1,5 +1,7 @@ package com.alibaba.arthas.tunnel.server; +import com.taobao.arthas.common.ArthasConstants; + import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; @@ -16,8 +18,6 @@ import io.netty.handler.ssl.SslContext; */ public class TunnelSocketServerInitializer extends ChannelInitializer { - private static final String WEBSOCKET_PATH = "/ws"; - private final SslContext sslCtx; private TunnelServer tunnelServer; @@ -34,9 +34,9 @@ public class TunnelSocketServerInitializer extends ChannelInitializer settings = new ArrayList(); + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public List getSettings() { + return settings; + } + + public void setSettings(List settings) { + this.settings = settings; + } + } + +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/EmbeddedRedisConfiguration.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/EmbeddedRedisConfiguration.java new file mode 100644 index 000000000..28ca1d27f --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/EmbeddedRedisConfiguration.java @@ -0,0 +1,37 @@ +package com.alibaba.arthas.tunnel.server.app.configuration; + +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.alibaba.arthas.tunnel.server.app.configuration.ArthasProperties.EmbeddedRedis; + +import redis.embedded.RedisServer; +import redis.embedded.RedisServerBuilder; + +/** + * + * @author hengyunabc 2020-11-03 + * + */ +@Configuration +@AutoConfigureBefore(TunnelClusterStoreConfiguration.class) +public class EmbeddedRedisConfiguration { + + @Bean(initMethod = "start", destroyMethod = "stop") + @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "arthas", name = { "embedded-redis.enabled" }) + public RedisServer embeddedRedisServer(ArthasProperties arthasProperties) { + EmbeddedRedis embeddedRedis = arthasProperties.getEmbeddedRedis(); + + RedisServerBuilder builder = RedisServer.builder().port(embeddedRedis.getPort()).bind(embeddedRedis.getHost()); + + for (String setting : embeddedRedis.getSettings()) { + builder.setting(setting); + } + RedisServer redisServer = builder.build(); + return redisServer; + } +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/TunnelClusterStoreConfiguration.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/TunnelClusterStoreConfiguration.java new file mode 100644 index 000000000..187d27d95 --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/TunnelClusterStoreConfiguration.java @@ -0,0 +1,55 @@ +package com.alibaba.arthas.tunnel.server.app.configuration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.data.redis.core.StringRedisTemplate; + +import com.alibaba.arthas.tunnel.server.app.configuration.TunnelClusterStoreConfiguration.RedisTunnelClusterStoreConfiguration; +import com.alibaba.arthas.tunnel.server.cluster.InMemoryClusterStore; +import com.alibaba.arthas.tunnel.server.cluster.RedisTunnelClusterStore; +import com.alibaba.arthas.tunnel.server.cluster.TunnelClusterStore; + +/** + * + * @author hengyunabc 2020-10-29 + * + */ +@Configuration +@AutoConfigureAfter(value = { RedisAutoConfiguration.class, CacheAutoConfiguration.class }) +@Import(RedisTunnelClusterStoreConfiguration.class) +public class TunnelClusterStoreConfiguration { + + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(name = "spring.cache.type", havingValue = "caffeine") + public TunnelClusterStore tunnelClusterStore(@Autowired CacheManager cacheManager) { + Cache inMemoryClusterCache = cacheManager.getCache("inMemoryClusterCache"); + InMemoryClusterStore inMemoryClusterStore = new InMemoryClusterStore(); + inMemoryClusterStore.setCache(inMemoryClusterCache); + return inMemoryClusterStore; + } + + static class RedisTunnelClusterStoreConfiguration { + @Bean + // @ConditionalOnBean(StringRedisTemplate.class) + @ConditionalOnClass(StringRedisTemplate.class) + @ConditionalOnProperty("spring.redis.host") + @ConditionalOnMissingBean + public TunnelClusterStore tunnelClusterStore(@Autowired StringRedisTemplate redisTemplate) { + RedisTunnelClusterStore redisTunnelClusterStore = new RedisTunnelClusterStore(); + redisTunnelClusterStore.setRedisTemplate(redisTemplate); + return redisTunnelClusterStore; + } + } + +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/TunnelServerConfiguration.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/TunnelServerConfiguration.java new file mode 100644 index 000000000..80fe4648d --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/configuration/TunnelServerConfiguration.java @@ -0,0 +1,41 @@ +package com.alibaba.arthas.tunnel.server.app.configuration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.alibaba.arthas.tunnel.server.TunnelServer; +import com.alibaba.arthas.tunnel.server.cluster.TunnelClusterStore; + +/** + * + * @author hengyunabc 2020-10-27 + * + */ +@Configuration +@AutoConfigureAfter(RedisAutoConfiguration.class) +public class TunnelServerConfiguration { + + @Autowired + ArthasProperties arthasProperties; + + @Bean(initMethod = "start", destroyMethod = "stop") + @ConditionalOnMissingBean + public TunnelServer tunnelServer(@Autowired(required = false) TunnelClusterStore tunnelClusterStore) { + TunnelServer tunnelServer = new TunnelServer(); + + tunnelServer.setHost(arthasProperties.getServer().getHost()); + tunnelServer.setPort(arthasProperties.getServer().getPort()); + tunnelServer.setSsl(arthasProperties.getServer().isSsl()); + tunnelServer.setPath(arthasProperties.getServer().getPath()); + tunnelServer.setClientConnectHost(arthasProperties.getServer().getClientConnectHost()); + if (tunnelClusterStore != null) { + tunnelServer.setTunnelClusterStore(tunnelClusterStore); + } + return tunnelServer; + } + +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/ClusterController.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/ClusterController.java new file mode 100644 index 000000000..86a56b572 --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/ClusterController.java @@ -0,0 +1,46 @@ +package com.alibaba.arthas.tunnel.server.app.web; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.arthas.tunnel.server.AgentClusterInfo; +import com.alibaba.arthas.tunnel.server.TunnelServer; +import com.alibaba.arthas.tunnel.server.cluster.TunnelClusterStore; + +/** + * + * @author hengyunabc 2020-10-27 + * + */ +@Controller +public class ClusterController { + private final static Logger logger = LoggerFactory.getLogger(ClusterController.class); + + @Autowired + TunnelServer tunnelServer; + + @RequestMapping(value = "/api/cluster/findHost") + @ResponseBody + public String execute(@RequestParam(value = "agentId", required = true) String agentId) { + TunnelClusterStore tunnelClusterStore = tunnelServer.getTunnelClusterStore(); + + String host = null; + if (tunnelClusterStore != null) { + AgentClusterInfo info = tunnelClusterStore.findAgent(agentId); + host = info.getClientConnectHost(); + } + + if (host == null) { + host = ""; + } + + logger.info("arthas cluster findHost, agentId: {}, host: {}", agentId, host); + + return host; + } +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java new file mode 100644 index 000000000..31fd608cc --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/DetailAPIController.java @@ -0,0 +1,114 @@ +package com.alibaba.arthas.tunnel.server.app.web; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.alibaba.arthas.tunnel.server.AgentClusterInfo; +import com.alibaba.arthas.tunnel.server.app.configuration.ArthasProperties; +import com.alibaba.arthas.tunnel.server.cluster.TunnelClusterStore; + +/** + * + * @author hengyunabc 2020-11-03 + * + */ +@Controller +public class DetailAPIController { + + private final static Logger logger = LoggerFactory.getLogger(DetailAPIController.class); + + @Autowired + ArthasProperties arthasProperties; + + @Autowired(required = false) + private TunnelClusterStore tunnelClusterStore; + + @RequestMapping("/api/tunnelApps") + @ResponseBody + public Set tunnelApps(HttpServletRequest request, Model model) { + if (!arthasProperties.isEnableDetailPages()) { + throw new IllegalAccessError("not allow"); + } + + Set result = new HashSet(); + + if (tunnelClusterStore != null) { + Collection agentIds = tunnelClusterStore.allAgentIds(); + + for (String id : agentIds) { + String appName = findAppNameFromAgentId(id); + if (appName != null) { + result.add(appName); + } else { + logger.warn("illegal agentId: " + id); + } + } + + } + + return result; + } + + @RequestMapping("/api/tunnelAgentInfo") + @ResponseBody + public Map tunnelAgentIds(@RequestParam(value = "app", required = true) String appName, + HttpServletRequest request, Model model) { + if (!arthasProperties.isEnableDetailPages()) { + throw new IllegalAccessError("not allow"); + } + + if (tunnelClusterStore != null) { + Map agentInfos = tunnelClusterStore.agentInfo(appName); + + return agentInfos; + } + + return Collections.emptyMap(); + } + + /** + * check if agentId exists + * @param agentId + * @return + */ + @RequestMapping("/api/tunnelAgents") + @ResponseBody + public Map tunnelAgentIds(@RequestParam(value = "agentId", required = true) String agentId) { + Map result = new HashMap(); + boolean success = false; + try { + AgentClusterInfo info = tunnelClusterStore.findAgent(agentId); + if (info != null) { + success = true; + } + } catch (Throwable e) { + logger.error("try to find agentId error, id: {}", agentId, e); + } + result.put("success", success); + return result; + } + + private static String findAppNameFromAgentId(String id) { + int index = id.indexOf('_'); + if (index < 0 || index >= id.length()) { + return null; + } + + return id.substring(0, index); + } +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/ProxyController.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/ProxyController.java new file mode 100644 index 000000000..3c7630aa6 --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/ProxyController.java @@ -0,0 +1,92 @@ +package com.alibaba.arthas.tunnel.server.app.web; + +import java.net.URI; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang3.RandomStringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.http.ResponseEntity.BodyBuilder; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.HandlerMapping; +import org.springframework.web.util.UriComponentsBuilder; + +import com.alibaba.arthas.tunnel.common.MethodConstants; +import com.alibaba.arthas.tunnel.common.SimpleHttpResponse; +import com.alibaba.arthas.tunnel.common.URIConstans; +import com.alibaba.arthas.tunnel.server.AgentInfo; +import com.alibaba.arthas.tunnel.server.TunnelServer; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.util.concurrent.GlobalEventExecutor; +import io.netty.util.concurrent.Promise; + +/** + * 代理http请求到具体的 arthas agent里 + * + * @author hengyunabc 2020-10-22 + * + */ +@Controller +public class ProxyController { + private final static Logger logger = LoggerFactory.getLogger(ProxyController.class); + + @Autowired + TunnelServer tunnelServer; + + @RequestMapping(value = "/proxy/{agentId}/**") + @ResponseBody + public ResponseEntity execute(@PathVariable(name = "agentId", required = true) String agentId, + HttpServletRequest request) throws InterruptedException, ExecutionException, TimeoutException { + + String fullPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); + String targetUrl = fullPath.substring("/proxy/".length() + agentId.length()); + + logger.info("http proxy, agentId: {}, targetUrl: {}", agentId, targetUrl); + + Optional findAgent = tunnelServer.findAgent(agentId); + + if (findAgent.isPresent()) { + String requestId = RandomStringUtils.random(20, true, true).toUpperCase(); + + ChannelHandlerContext agentCtx = findAgent.get().getChannelHandlerContext(); + + Promise httpResponsePromise = GlobalEventExecutor.INSTANCE.newPromise(); + + tunnelServer.addProxyRequestPromise(requestId, httpResponsePromise); + + URI uri = UriComponentsBuilder.newInstance().scheme(URIConstans.RESPONSE).path("/") + .queryParam(URIConstans.METHOD, MethodConstants.HTTP_PROXY).queryParam(URIConstans.ID, agentId) + .queryParam(URIConstans.TARGET_URL, targetUrl).queryParam(URIConstans.PROXY_REQUEST_ID, requestId) + .build().toUri(); + + agentCtx.channel().writeAndFlush(new TextWebSocketFrame(uri.toString())); + logger.info("waitting for arthas agent http proxy, agentId: {}, targetUrl: {}", agentId, targetUrl); + + SimpleHttpResponse simpleHttpResponse = httpResponsePromise.get(15, TimeUnit.SECONDS); + + BodyBuilder bodyBuilder = ResponseEntity.status(simpleHttpResponse.getStatus()); + for (Entry entry : simpleHttpResponse.getHeaders().entrySet()) { + bodyBuilder.header(entry.getKey(), entry.getValue()); + } + ResponseEntity responseEntity = bodyBuilder.body(simpleHttpResponse.getContent()); + return responseEntity; + } else { + logger.error("can not find agent by agentId: {}", agentId); + } + + return ResponseEntity.notFound().build(); + } +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/StatController.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/StatController.java index 11cb411a8..409ef1a29 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/StatController.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/app/web/StatController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; /** - * + * arthas agent数据回报的演示接口 * @author hengyunabc 2019-09-24 * */ diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/InMemoryClusterStore.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/InMemoryClusterStore.java new file mode 100644 index 000000000..944724667 --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/InMemoryClusterStore.java @@ -0,0 +1,87 @@ +package com.alibaba.arthas.tunnel.server.cluster; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cache.Cache; +import org.springframework.cache.Cache.ValueWrapper; +import org.springframework.cache.caffeine.CaffeineCache; + +import com.alibaba.arthas.tunnel.server.AgentClusterInfo; + +/** + * + * @author hengyunabc 2020-12-02 + * + */ +public class InMemoryClusterStore implements TunnelClusterStore { + private final static Logger logger = LoggerFactory.getLogger(InMemoryClusterStore.class); + + private Cache cache; + + @Override + public AgentClusterInfo findAgent(String agentId) { + + ValueWrapper valueWrapper = cache.get(agentId); + if (valueWrapper == null) { + return null; + } + + AgentClusterInfo info = (AgentClusterInfo) valueWrapper.get(); + return info; + } + + @Override + public void removeAgent(String agentId) { + cache.evict(agentId); + } + + @Override + public void addAgent(String agentId, AgentClusterInfo info, long timeout, TimeUnit timeUnit) { + cache.put(agentId, info); + } + + @Override + public Collection allAgentIds() { + CaffeineCache caffeineCache = (CaffeineCache) cache; + com.github.benmanes.caffeine.cache.Cache nativeCache = caffeineCache.getNativeCache(); + return (Collection) (Collection) nativeCache.asMap().keySet(); + } + + @Override + public Map agentInfo(String appName) { + CaffeineCache caffeineCache = (CaffeineCache) cache; + com.github.benmanes.caffeine.cache.Cache nativeCache = caffeineCache.getNativeCache(); + + ConcurrentMap map = (ConcurrentMap) (ConcurrentMap) nativeCache + .asMap(); + + Map result = new HashMap(); + + String prefix = appName + "_"; + for (Entry entry : map.entrySet()) { + String agentId = entry.getKey(); + if (agentId.startsWith(prefix)) { + result.put(agentId, entry.getValue()); + } + } + + return result; + + } + + public Cache getCache() { + return cache; + } + + public void setCache(Cache cache) { + this.cache = cache; + } + +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/RedisTunnelClusterStore.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/RedisTunnelClusterStore.java new file mode 100644 index 000000000..5721bdeb8 --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/RedisTunnelClusterStore.java @@ -0,0 +1,122 @@ +package com.alibaba.arthas.tunnel.server.cluster; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; + +import com.alibaba.arthas.tunnel.server.AgentClusterInfo; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * + * @author hengyunabc 2020-10-27 + * + */ +public class RedisTunnelClusterStore implements TunnelClusterStore { + private final static Logger logger = LoggerFactory.getLogger(RedisTunnelClusterStore.class); + // 定义jackson对象 + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private String prefix = "arthas-tunnel-agent-"; + + private StringRedisTemplate redisTemplate; + + @Override + public AgentClusterInfo findAgent(String agentId) { + try { + ValueOperations opsForValue = redisTemplate.opsForValue(); + String infoStr = opsForValue.get(prefix + agentId); + AgentClusterInfo info = MAPPER.readValue(infoStr, AgentClusterInfo.class); + return info; + } catch (Throwable e) { + logger.error("try to read agentInfo error. agentId:{}", agentId, e); + throw new RuntimeException(e); + } + } + + @Override + public void removeAgent(String agentId) { + ValueOperations opsForValue = redisTemplate.opsForValue(); + opsForValue.getOperations().delete(prefix + agentId); + } + + @Override + public void addAgent(String agentId, AgentClusterInfo info, long timeout, TimeUnit timeUnit) { + try { + ValueOperations opsForValue = redisTemplate.opsForValue(); + String infoStr = MAPPER.writeValueAsString(info); + opsForValue.set(prefix + agentId, infoStr, timeout, timeUnit); + } catch (Throwable e) { + logger.error("try to add agentInfo error. agentId:{}", agentId, e); + throw new RuntimeException(e); + } + } + + public StringRedisTemplate getRedisTemplate() { + return redisTemplate; + } + + public void setRedisTemplate(StringRedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + @Override + public Collection allAgentIds() { + ValueOperations opsForValue = redisTemplate.opsForValue(); + + Set result = new HashSet(); + + int length = prefix.length(); + for (String value : opsForValue.getOperations().keys(prefix + "*")) { + result.add(value.substring(length)); + + } + return result; + } + + @Override + public Map agentInfo(String appName) { + try { + + ValueOperations opsForValue = redisTemplate.opsForValue(); + + Set keys = new HashSet(); + + String prefixWithAppName = prefix + appName + "_"; + + for (String value : opsForValue.getOperations().keys(prefixWithAppName + "*")) { + keys.add(value); + + } + + List values = opsForValue.getOperations().opsForValue().multiGet(keys); + + Map result = new HashMap<>(); + + Iterator iterator = values.iterator(); + + for (String key : keys) { + String infoStr = iterator.next(); + AgentClusterInfo info = MAPPER.readValue(infoStr, AgentClusterInfo.class); + String agentId = key.substring(prefix.length()); + result.put(agentId, info); + } + + return result; + } catch (Throwable e) { + logger.error("try to query agentInfo error. appName:{}", appName, e); + throw new RuntimeException(e); + } + } + +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/TunnelClusterStore.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/TunnelClusterStore.java new file mode 100644 index 000000000..e03b31e58 --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/cluster/TunnelClusterStore.java @@ -0,0 +1,25 @@ +package com.alibaba.arthas.tunnel.server.cluster; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.alibaba.arthas.tunnel.server.AgentClusterInfo; + +/** + * 保存agentId连接到哪个具体的 tunnel server,集群部署时使用 + * + * @author hengyunabc 2020-10-27 + * + */ +public interface TunnelClusterStore { + public void addAgent(String agentId, AgentClusterInfo info, long expire, TimeUnit timeUnit); + + public AgentClusterInfo findAgent(String agentId); + + public void removeAgent(String agentId); + + public Collection allAgentIds(); + + public Map agentInfo(String appName); +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndPointAutoconfiguration.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndPointAutoconfiguration.java index 51682c2ff..6faa73321 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndPointAutoconfiguration.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndPointAutoconfiguration.java @@ -6,7 +6,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.alibaba.arthas.tunnel.server.app.ArthasProperties; +import com.alibaba.arthas.tunnel.server.app.configuration.ArthasProperties; @EnableConfigurationProperties(ArthasProperties.class) @Configuration diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndpoint.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndpoint.java index 0438f511a..10563b400 100644 --- a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndpoint.java +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/endpoint/ArthasEndpoint.java @@ -8,7 +8,7 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import com.alibaba.arthas.tunnel.server.TunnelServer; -import com.alibaba.arthas.tunnel.server.app.ArthasProperties; +import com.alibaba.arthas.tunnel.server.app.configuration.ArthasProperties; @Endpoint(id = "arthas") public class ArthasEndpoint { diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/utils/HttpUtils.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/utils/HttpUtils.java new file mode 100644 index 000000000..cdfd1360e --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/utils/HttpUtils.java @@ -0,0 +1,31 @@ +package com.alibaba.arthas.tunnel.server.utils; + +import io.netty.handler.codec.http.HttpHeaders; + +/** + * + * @author hengyunabc 2021-02-26 + * + */ +public class HttpUtils { + + public static String findClientIP(HttpHeaders headers) { + String hostStr = headers.get("X-Forwarded-For"); + if (hostStr == null) { + return null; + } + int index = hostStr.indexOf(','); + if (index > 0) { + hostStr = hostStr.substring(0, index); + } + return hostStr; + } + + public static Integer findClientPort(HttpHeaders headers) { + String portStr = headers.get("X-Real-Port"); + if (portStr != null) { + return Integer.parseInt(portStr); + } + return null; + } +} diff --git a/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/utils/InetAddressUtil.java b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/utils/InetAddressUtil.java new file mode 100644 index 000000000..0c4efe1af --- /dev/null +++ b/tunnel-server/src/main/java/com/alibaba/arthas/tunnel/server/utils/InetAddressUtil.java @@ -0,0 +1,51 @@ +package com.alibaba.arthas.tunnel.server.utils; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author hengyunabc 2020-10-27 + * + */ +public class InetAddressUtil { + private final static Logger logger = LoggerFactory.getLogger(InetAddressUtil.class); + + /** + * 获得本机IP。 + *

+ * 在超过一块网卡时会有问题,因为这里每次都只是取了第一块网卡绑定的IP地址 + */ + public static String getInetAddress() { + try { + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + InetAddress address = null; + while (interfaces.hasMoreElements()) { + NetworkInterface ni = interfaces.nextElement(); + Enumeration addresses = ni.getInetAddresses(); + while (addresses.hasMoreElements()) { + address = addresses.nextElement(); + if (isValidAddress(address)) { + return address.getHostAddress(); + } + } + } + logger.warn("Can not get the server IP address"); + return null; + } catch (Throwable t) { + logger.error("Can not get the server IP address", t); + return null; + } + } + + public static boolean isValidAddress(InetAddress address) { + return address != null && !address.isLoopbackAddress() // filter 127.x.x.x + && !address.isAnyLocalAddress() // filter 0.0.0.0 + && !address.isLinkLocalAddress() // filter 169.254.0.0/16 + && !address.getHostAddress().contains(":");// filter IPv6 + } +} diff --git a/tunnel-server/src/main/resources/application.properties b/tunnel-server/src/main/resources/application.properties index decaf19fa..81a8cdfec 100755 --- a/tunnel-server/src/main/resources/application.properties +++ b/tunnel-server/src/main/resources/application.properties @@ -1,8 +1,20 @@ - -# arthas http port +# arthas tunnel server host +arthas.server.host=0.0.0.0 +# arthas tunnel server port arthas.server.port=7777 + # for all endpoints management.endpoints.web.exposure.include=* # default user name -spring.security.user.name=arthas \ No newline at end of file +spring.security.user.name=arthas + + +arthas.enable-detail-pages=true +spring.cache.type=caffeine +spring.cache.cache-names=inMemoryClusterCache +spring.cache.caffeine.spec=maximumSize=3000,expireAfterAccess=3600s + +#arthas.embedded-redis.enabled=true +#arthas.embedded-redis.settings=maxmemory 128M +#spring.redis.host=127.0.0.1 diff --git a/tunnel-server/src/main/resources/static/agents.html b/tunnel-server/src/main/resources/static/agents.html new file mode 100644 index 000000000..a5505c8ea --- /dev/null +++ b/tunnel-server/src/main/resources/static/agents.html @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + Arthas Tutorials + + + + + + + + + + + +

+ + + + + + + + + + + + + + + + +
IPAgentIdVersion
+ {{agentInfo.host}} + + {{agentId}} + + {{agentInfo.arthasVersion}} +
+ +
+ + + + + \ No newline at end of file diff --git a/tunnel-server/src/main/resources/static/apps.html b/tunnel-server/src/main/resources/static/apps.html new file mode 100644 index 000000000..285c3261d --- /dev/null +++ b/tunnel-server/src/main/resources/static/apps.html @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + Arthas Tutorials + + + + + + + + + + + +
+ + + + + + + + + + + + +
应用名
+ {{myApp}} +
+ +
+ + + + + \ No newline at end of file diff --git a/tunnel-server/src/main/resources/static/index.html b/tunnel-server/src/main/resources/static/index.html index a55b8fb0d..4ac11f30f 100644 --- a/tunnel-server/src/main/resources/static/index.html +++ b/tunnel-server/src/main/resources/static/index.html @@ -90,6 +90,7 @@
+ Arthas Output
diff --git a/tunnel-server/src/main/resources/static/web-console.js b/tunnel-server/src/main/resources/static/web-console.js index d10d9fb73..31905bd54 100644 --- a/tunnel-server/src/main/resources/static/web-console.js +++ b/tunnel-server/src/main/resources/static/web-console.js @@ -77,10 +77,13 @@ function getTerminalSize () { } /** init websocket **/ -function initWs (ip, port, agentId) { +function initWs (ip, port, path, agentId, targetServer) { var protocol= location.protocol === 'https:' ? 'wss://' : 'ws://'; - var path = protocol + ip + ':' + port + '/ws?method=connectArthas&id=' + agentId; - ws = new WebSocket(path); + var uri = protocol + ip + ':' + port + '/' + encodeURIComponent(path) + '?method=connectArthas&id=' + agentId; + if (targetServer != null) { + uri = uri + '&targetServer=' + encodeURIComponent(targetServer); + } + ws = new WebSocket(uri); } /** init xterm **/ @@ -114,8 +117,16 @@ function startConnect (silent) { alert('Already connected'); return; } + + var path = getUrlParam('path'); + if (path == null) { + path = "ws"; + } + + var targetServer = getUrlParam('targetServer'); + // init webSocket - initWs(ip, port, agentId); + initWs(ip, port, path, agentId, targetServer); ws.onerror = function () { ws.close(); ws = null; @@ -167,6 +178,10 @@ function disconnect () { } } +function updateArthasOutputLink() { + $('#arthasOutputA').prop("href", "proxy/" + $('#agentId').val() + "/arthas-output/") +} + /** full screen show **/ function xtermFullScreen () { var ele = document.getElementById('terminal-card'); diff --git a/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/URITest.java b/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/URITest.java new file mode 100644 index 000000000..92607597a --- /dev/null +++ b/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/URITest.java @@ -0,0 +1,67 @@ +package com.alibaba.arthas.tunnel.server; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.springframework.web.util.UriComponentsBuilder; + +import com.alibaba.arthas.tunnel.common.MethodConstants; +import com.alibaba.arthas.tunnel.common.URIConstans; + +/** + * + * @author hengyunabc 2020-10-22 + * + */ +public class URITest { + @Test + public void test() throws URISyntaxException { + String id = "xxx"; + URI responseUri = new URI("response", null, "/", "method=" + MethodConstants.AGENT_REGISTER + "&id=" + id, + null); + + String string = responseUri.toString(); + + String uriString = UriComponentsBuilder.newInstance().scheme("response").path("/") + .queryParam("method", MethodConstants.AGENT_REGISTER).queryParam("id", id).build().toUriString(); + + Assertions.assertThat(string).isEqualTo(uriString).isEqualTo("response:/?method=agentRegister&id=xxx"); + } + + @Test + public void testEncode() throws URISyntaxException { + String id = "xxx/%ff#ff"; + URI responseUri = new URI("response", null, "/", "method=" + MethodConstants.AGENT_REGISTER + "&id=" + id, + null); + + String string = responseUri.toString(); + + String uriString = UriComponentsBuilder.newInstance().scheme(URIConstans.RESPONSE).path("/") + .queryParam(URIConstans.METHOD, MethodConstants.AGENT_REGISTER).queryParam(URIConstans.ID, id).build() + .encode().toUriString(); + + Assertions.assertThat(string).isEqualTo(uriString) + .isEqualTo("response:/?method=agentRegister&id=xxx/%25ff%23ff"); + } + + @Test + public void test3() throws URISyntaxException { + + String agentId = "ffff"; + String clientConnectionId = "ccccc"; + URI uri = new URI("response", null, "/", "method=" + MethodConstants.START_TUNNEL + "&id=" + agentId + + "&clientConnectionId=" + clientConnectionId, null); + + String string = uri.toString(); + + String uriString = UriComponentsBuilder.newInstance().scheme(URIConstans.RESPONSE).path("/") + .queryParam(URIConstans.METHOD, MethodConstants.START_TUNNEL).queryParam(URIConstans.ID, agentId) + .queryParam(URIConstans.CLIENT_CONNECTION_ID, clientConnectionId).build().toUriString(); + + System.err.println(string); + Assertions.assertThat(string).isEqualTo(uriString) + .isEqualTo("response:/?method=startTunnel&id=ffff&clientConnectionId=ccccc"); + } +} diff --git a/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/app/ArthasTunnelApplicationTest.java b/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/app/ArthasTunnelApplicationTest.java new file mode 100644 index 000000000..50e026324 --- /dev/null +++ b/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/app/ArthasTunnelApplicationTest.java @@ -0,0 +1,22 @@ +package com.alibaba.arthas.tunnel.server.app; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * + * @author hengyunabc 2021-07-12 + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = { ArthasTunnelApplication.class }) +public class ArthasTunnelApplicationTest { + + @Test + public void contextLoads() { + System.out.println("hello"); + } + +} \ No newline at end of file diff --git a/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/utils/HttpUtilsTest.java b/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/utils/HttpUtilsTest.java new file mode 100644 index 000000000..9db6b870c --- /dev/null +++ b/tunnel-server/src/test/java/com/alibaba/arthas/tunnel/server/utils/HttpUtilsTest.java @@ -0,0 +1,47 @@ +package com.alibaba.arthas.tunnel.server.utils; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.mockito.Mockito; + +import io.netty.handler.codec.http.HttpHeaders; + +/** + * + * @author hengyunabc 2021-02-26 + * + */ +public class HttpUtilsTest { + + @Test + public void test1() { + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + Mockito.when(headers.get("X-Forwarded-For")).thenReturn("30.25.233.172, 11.162.179.161"); + + String ip = HttpUtils.findClientIP(headers); + + Assertions.assertThat(ip).isEqualTo("30.25.233.172"); + } + + @Test + public void test2() { + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + Mockito.when(headers.get("X-Forwarded-For")).thenReturn("30.25.233.172"); + + String ip = HttpUtils.findClientIP(headers); + + Assertions.assertThat(ip).isEqualTo("30.25.233.172"); + + } + + @Test + public void test3() { + HttpHeaders headers = Mockito.mock(HttpHeaders.class); + Mockito.when(headers.get("X-Forwarded-For")).thenReturn(null); + + String ip = HttpUtils.findClientIP(headers); + + Assertions.assertThat(ip).isEqualTo(null); + + } +} diff --git a/tutorials/katacoda/arthas-advanced-cn/case-classloader.md b/tutorials/katacoda/arthas-advanced-cn/case-classloader.md index 110cdca4c..a7754a277 100644 --- a/tutorials/katacoda/arthas-advanced-cn/case-classloader.md +++ b/tutorials/katacoda/arthas-advanced-cn/case-classloader.md @@ -38,7 +38,7 @@ $ classloader -l 列出上面的`org.apache.jasper.servlet.JasperLoader`加载的类: -`classloader -a --classLoaderClass apache.jasper.servlet.JasperLoader`{{execute T2}} +`classloader -a --classLoaderClass org.apache.jasper.servlet.JasperLoader`{{execute T2}} ```bash $ classloader -a --classLoaderClass apache.jasper.servlet.JasperLoader diff --git a/tutorials/katacoda/arthas-advanced-cn/index.json b/tutorials/katacoda/arthas-advanced-cn/index.json index 7f9aea853..337c44695 100644 --- a/tutorials/katacoda/arthas-advanced-cn/index.json +++ b/tutorials/katacoda/arthas-advanced-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动demo", + "title": "启动math-game", "text": "start-demo.md" }, { @@ -98,7 +98,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/arthas-advanced-en/case-classloader.md b/tutorials/katacoda/arthas-advanced-en/case-classloader.md index 2e4717159..d93257918 100644 --- a/tutorials/katacoda/arthas-advanced-en/case-classloader.md +++ b/tutorials/katacoda/arthas-advanced-en/case-classloader.md @@ -38,7 +38,7 @@ $ classloader -l List all classes loaded by `org.apache.jasper.servlet.JasperLoader`: -`classloader -a --classLoaderClass apache.jasper.servlet.JasperLoader`{{execute T2}} +`classloader -a --classLoaderClass org.apache.jasper.servlet.JasperLoader`{{execute T2}} ```bash $ classloader -a --classLoaderClass apache.jasper.servlet.JasperLoader diff --git a/tutorials/katacoda/arthas-advanced-en/index.json b/tutorials/katacoda/arthas-advanced-en/index.json index 71f39dfc9..eba999d71 100644 --- a/tutorials/katacoda/arthas-advanced-en/index.json +++ b/tutorials/katacoda/arthas-advanced-en/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -98,7 +98,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/arthas-basics-cn/arthas-demo.md b/tutorials/katacoda/arthas-basics-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/arthas-basics-cn/arthas-demo.md +++ b/tutorials/katacoda/arthas-basics-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/arthas-basics-cn/index.json b/tutorials/katacoda/arthas-basics-cn/index.json index 72b69e4ce..cc719f6ca 100644 --- a/tutorials/katacoda/arthas-basics-cn/index.json +++ b/tutorials/katacoda/arthas-basics-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -31,6 +31,10 @@ "title": "Watch", "text": "watch.md" }, + { + "title": "Vmtool", + "text": "vmtool.md" + }, { "title": "Exit/Stop", "text": "exit.md" @@ -47,7 +51,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/arthas-basics-cn/vmtool.md b/tutorials/katacoda/arthas-basics-cn/vmtool.md new file mode 100644 index 000000000..5aed3cfe3 --- /dev/null +++ b/tutorials/katacoda/arthas-basics-cn/vmtool.md @@ -0,0 +1,20 @@ + +通过`vmtool`命令,可以搜索内存对象。 + +`vmtool --action getInstances --className java.lang.String --limit 10`{{execute T2}} + +```bash +$ vmtool --action getInstances --className java.lang.String --limit 10 +@String[][ + @String[com/taobao/arthas/core/shell/session/Session], + @String[com.taobao.arthas.core.shell.session.Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/], + @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], + @String[java/util/concurrent/locks/LockSupport], +] +``` \ No newline at end of file diff --git a/tutorials/katacoda/arthas-basics-en/arthas-demo.md b/tutorials/katacoda/arthas-basics-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/arthas-basics-en/arthas-demo.md +++ b/tutorials/katacoda/arthas-basics-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/arthas-basics-en/index.json b/tutorials/katacoda/arthas-basics-en/index.json index 154d7ad5e..a5de80d5a 100644 --- a/tutorials/katacoda/arthas-basics-en/index.json +++ b/tutorials/katacoda/arthas-basics-en/index.json @@ -31,6 +31,10 @@ "title": "Watch", "text": "watch.md" }, + { + "title": "Vmtool", + "text": "vmtool.md" + }, { "title": "Exit/Stop", "text": "exit.md" @@ -47,7 +51,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/arthas-basics-en/vmtool.md b/tutorials/katacoda/arthas-basics-en/vmtool.md new file mode 100644 index 000000000..3e45a6cc4 --- /dev/null +++ b/tutorials/katacoda/arthas-basics-en/vmtool.md @@ -0,0 +1,20 @@ + +The `vmtool` command can search object in JVM. + +`vmtool --action getInstances --className java.lang.String --limit 10`{{execute T2}} + +```bash +$ vmtool --action getInstances --className java.lang.String --limit 10 +@String[][ + @String[com/taobao/arthas/core/shell/session/Session], + @String[com.taobao.arthas.core.shell.session.Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/taobao/arthas/core/shell/session/Session.class], + @String[com/], + @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], + @String[java/util/concurrent/locks/LockSupport], +] +``` \ No newline at end of file diff --git a/tutorials/katacoda/case-async-jobs-cn/arthas-demo.md b/tutorials/katacoda/case-async-jobs-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/case-async-jobs-cn/arthas-demo.md +++ b/tutorials/katacoda/case-async-jobs-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/case-async-jobs-cn/index.json b/tutorials/katacoda/case-async-jobs-cn/index.json index 84728cc8d..415036802 100644 --- a/tutorials/katacoda/case-async-jobs-cn/index.json +++ b/tutorials/katacoda/case-async-jobs-cn/index.json @@ -57,7 +57,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-async-jobs-en/arthas-demo.md b/tutorials/katacoda/case-async-jobs-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/case-async-jobs-en/arthas-demo.md +++ b/tutorials/katacoda/case-async-jobs-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/case-async-jobs-en/index.json b/tutorials/katacoda/case-async-jobs-en/index.json index 62580f5c4..4ba8c322b 100644 --- a/tutorials/katacoda/case-async-jobs-en/index.json +++ b/tutorials/katacoda/case-async-jobs-en/index.json @@ -57,7 +57,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-boot-details-cn/arthas-boot-details.md b/tutorials/katacoda/case-boot-details-cn/arthas-boot-details.md index 7df3305b1..975d300b4 100644 --- a/tutorials/katacoda/case-boot-details-cn/arthas-boot-details.md +++ b/tutorials/katacoda/case-boot-details-cn/arthas-boot-details.md @@ -29,7 +29,7 @@ EXAMPLES: java -jar arthas-boot.jar -f batch.as java -jar arthas-boot.jar --use-version 3.3.6 java -jar arthas-boot.jar --versions - java -jar arthas-boot.jar --select arthas-demo + java -jar arthas-boot.jar --select math-game java -jar arthas-boot.jar --session-timeout 3600 java -jar arthas-boot.jar --attach-only java -jar arthas-boot.jar --repo-mirror aliyun --use-http diff --git a/tutorials/katacoda/case-boot-details-cn/arthas-demo.md b/tutorials/katacoda/case-boot-details-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/case-boot-details-cn/arthas-demo.md +++ b/tutorials/katacoda/case-boot-details-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/case-boot-details-cn/boot-examples.md b/tutorials/katacoda/case-boot-details-cn/boot-examples.md index d26619032..60e334457 100644 --- a/tutorials/katacoda/case-boot-details-cn/boot-examples.md +++ b/tutorials/katacoda/case-boot-details-cn/boot-examples.md @@ -67,7 +67,7 @@ 通过`--select`参数类名或者jar文件名指定目标进程 -`java -jar arthas-boot.jar --select arthas-demo`{{execute T2}} +`java -jar arthas-boot.jar --select math-game`{{execute T2}} ## 指定会话超时秒数 @@ -101,7 +101,7 @@ 比如下载全量的arthas zip包,解压之后以 -javaagent 的参数指定arthas-agent.jar来启动: -`java -javaagent:/tmp/test/arthas-agent.jar -jar arthas-demo.jar` +`java -javaagent:/tmp/test/arthas-agent.jar -jar math-game.jar` 默认的配置项在解压目录里的arthas.properties文件里。 diff --git a/tutorials/katacoda/case-boot-details-cn/index.json b/tutorials/katacoda/case-boot-details-cn/index.json index 56ad88414..5f752fadb 100644 --- a/tutorials/katacoda/case-boot-details-cn/index.json +++ b/tutorials/katacoda/case-boot-details-cn/index.json @@ -43,7 +43,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-boot-details-en/arthas-boot-details.md b/tutorials/katacoda/case-boot-details-en/arthas-boot-details.md index 7d692dff6..f80592380 100644 --- a/tutorials/katacoda/case-boot-details-en/arthas-boot-details.md +++ b/tutorials/katacoda/case-boot-details-en/arthas-boot-details.md @@ -32,7 +32,7 @@ EXAMPLES: java -jar arthas-boot.jar -f batch.as java -jar arthas-boot.jar --use-version 3.3.6 java -jar arthas-boot.jar --versions - java -jar arthas-boot.jar --select arthas-demo + java -jar arthas-boot.jar --select math-game java -jar arthas-boot.jar --session-timeout 3600 java -jar arthas-boot.jar --attach-only java -jar arthas-boot.jar --repo-mirror aliyun --use-http diff --git a/tutorials/katacoda/case-boot-details-en/arthas-demo.md b/tutorials/katacoda/case-boot-details-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/case-boot-details-en/arthas-demo.md +++ b/tutorials/katacoda/case-boot-details-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/case-boot-details-en/boot-examples.md b/tutorials/katacoda/case-boot-details-en/boot-examples.md index d528c7aa4..b04113698 100644 --- a/tutorials/katacoda/case-boot-details-en/boot-examples.md +++ b/tutorials/katacoda/case-boot-details-en/boot-examples.md @@ -64,7 +64,7 @@ Use `--batch-file` or `-f` to specify batch file to execute and target pid. Use `--select` to select target process by classname or JARfilename. -`java -jar arthas-boot.jar --select arthas-demo`{{execute T2}} +`java -jar arthas-boot.jar --select math-game`{{execute T2}} ## Specify session timeout seconds @@ -98,7 +98,7 @@ Usually Arthas dynamic attach the applications on the fly, but from version 3.2. For example, download the full arthas zip package, decompress it and start it by specifying arthas-agent.jar with the parameter -javaagent. -`java -javaagent:/tmp/test/arthas-agent.jar -jar arthas-demo.jar` +`java -javaagent:/tmp/test/arthas-agent.jar -jar math-game.jar` The default configuration is in the arthas.properties file in the decompression directory. diff --git a/tutorials/katacoda/case-boot-details-en/index.json b/tutorials/katacoda/case-boot-details-en/index.json index f07bb4c90..292b2caf1 100644 --- a/tutorials/katacoda/case-boot-details-en/index.json +++ b/tutorials/katacoda/case-boot-details-en/index.json @@ -43,7 +43,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-classloader-cn/index.json b/tutorials/katacoda/case-classloader-cn/index.json index 6b14362a5..6c038f648 100644 --- a/tutorials/katacoda/case-classloader-cn/index.json +++ b/tutorials/katacoda/case-classloader-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-classloader-en/index.json b/tutorials/katacoda/case-classloader-en/index.json index b081b7e00..b422269e2 100644 --- a/tutorials/katacoda/case-classloader-en/index.json +++ b/tutorials/katacoda/case-classloader-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-cn/index.json b/tutorials/katacoda/case-get-spring-context-cn/index.json index 2692dfc75..a8e6ecdf1 100644 --- a/tutorials/katacoda/case-get-spring-context-cn/index.json +++ b/tutorials/katacoda/case-get-spring-context-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-get-spring-context-en/index.json b/tutorials/katacoda/case-get-spring-context-en/index.json index fc8a51f57..1fe6fb36e 100644 --- a/tutorials/katacoda/case-get-spring-context-en/index.json +++ b/tutorials/katacoda/case-get-spring-context-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-http-401-cn/index.json b/tutorials/katacoda/case-http-401-cn/index.json index 688adefbb..242b57832 100644 --- a/tutorials/katacoda/case-http-401-cn/index.json +++ b/tutorials/katacoda/case-http-401-cn/index.json @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-http-401-en/index.json b/tutorials/katacoda/case-http-401-en/index.json index b0b51d052..a56942099 100644 --- a/tutorials/katacoda/case-http-401-en/index.json +++ b/tutorials/katacoda/case-http-401-en/index.json @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-http-404-cn/index.json b/tutorials/katacoda/case-http-404-cn/index.json index a410a6a3b..615fdc638 100644 --- a/tutorials/katacoda/case-http-404-cn/index.json +++ b/tutorials/katacoda/case-http-404-cn/index.json @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-http-404-en/index.json b/tutorials/katacoda/case-http-404-en/index.json index c32089283..474d22d36 100644 --- a/tutorials/katacoda/case-http-404-en/index.json +++ b/tutorials/katacoda/case-http-404-en/index.json @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-http-api-cn/arthas-demo.md b/tutorials/katacoda/case-http-api-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/case-http-api-cn/arthas-demo.md +++ b/tutorials/katacoda/case-http-api-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/case-http-api-cn/classpath-java-app.md b/tutorials/katacoda/case-http-api-cn/classpath-java-app.md index 1c8a39f86..7825b43ce 100644 --- a/tutorials/katacoda/case-http-api-cn/classpath-java-app.md +++ b/tutorials/katacoda/case-http-api-cn/classpath-java-app.md @@ -20,7 +20,7 @@ echo "classpath: $class_path"`{{execute T3}} 输出内容: ``` -classpath: arthas-demo.jar +classpath: math-game.jar ``` 注意: diff --git a/tutorials/katacoda/case-http-api-cn/index.json b/tutorials/katacoda/case-http-api-cn/index.json index f9535b927..81ee85a59 100644 --- a/tutorials/katacoda/case-http-api-cn/index.json +++ b/tutorials/katacoda/case-http-api-cn/index.json @@ -56,7 +56,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-http-api-en/arthas-demo.md b/tutorials/katacoda/case-http-api-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/case-http-api-en/arthas-demo.md +++ b/tutorials/katacoda/case-http-api-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/case-http-api-en/classpath-java-app.md b/tutorials/katacoda/case-http-api-en/classpath-java-app.md index ea49c354b..ebaac2fab 100644 --- a/tutorials/katacoda/case-http-api-en/classpath-java-app.md +++ b/tutorials/katacoda/case-http-api-en/classpath-java-app.md @@ -21,7 +21,7 @@ echo "classpath: $class_path"`{{execute T3}} Output: ``` -classpath: arthas-demo.jar +classpath: math-game.jar ``` NOTE: diff --git a/tutorials/katacoda/case-http-api-en/index.json b/tutorials/katacoda/case-http-api-en/index.json index 9474d3422..5119060dc 100644 --- a/tutorials/katacoda/case-http-api-en/index.json +++ b/tutorials/katacoda/case-http-api-en/index.json @@ -56,7 +56,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-jad-mc-redefine-cn/index.json b/tutorials/katacoda/case-jad-mc-redefine-cn/index.json index 1b88e7039..829c4d845 100644 --- a/tutorials/katacoda/case-jad-mc-redefine-cn/index.json +++ b/tutorials/katacoda/case-jad-mc-redefine-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-jad-mc-redefine-en/index.json b/tutorials/katacoda/case-jad-mc-redefine-en/index.json index eef3f947d..10aaa32ca 100644 --- a/tutorials/katacoda/case-jad-mc-redefine-en/index.json +++ b/tutorials/katacoda/case-jad-mc-redefine-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-logger-config-problem-cn/index.json b/tutorials/katacoda/case-logger-config-problem-cn/index.json index b14f3c41d..04099a90d 100644 --- a/tutorials/katacoda/case-logger-config-problem-cn/index.json +++ b/tutorials/katacoda/case-logger-config-problem-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-logger-config-problem-en/index.json b/tutorials/katacoda/case-logger-config-problem-en/index.json index 0cd78b0fd..736677778 100644 --- a/tutorials/katacoda/case-logger-config-problem-en/index.json +++ b/tutorials/katacoda/case-logger-config-problem-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-cn/finish.md b/tutorials/katacoda/case-ognl-practise-cn/finish.md new file mode 100644 index 000000000..1eceecb80 --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-cn/finish.md @@ -0,0 +1,20 @@ +我们演示如何调试Arthas的`ognl`表达式。如果有更多的技巧或者使用疑问,欢迎在Issue里提出。 + + +更多参考: + +* 特殊用法请参考:[https://github.com/alibaba/arthas/issues/71](https://github.com/alibaba/arthas/issues/71) +* OGNL表达式官网:[https://commons.apache.org/proper/commons-ognl/language-guide.html](https://commons.apache.org/proper/commons-ognl/language-guide.html) + + +--- + +* Issues: https://github.com/alibaba/arthas/issues +* 文档: https://arthas.aliyun.com/doc + +如果您在使用Arthas,请让我们知道。您的使用对我们非常重要:[查看](https://github.com/alibaba/arthas/issues/111) + +欢迎关注公众号,获取Arthas项目的信息、源码分析、案例实践。 + +![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg) + diff --git a/tutorials/katacoda/case-ognl-practise-cn/index.json b/tutorials/katacoda/case-ognl-practise-cn/index.json new file mode 100644 index 000000000..f2e8626ba --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-cn/index.json @@ -0,0 +1,29 @@ +{ + "title": "调试 Arthas 的 ognl 表达式", + "description": "调试 Arthas 的 ognl 表达式", + "details": { + "steps": [ + { + "text": "step1.md", + "code": "setup.sh" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + } + }, + "files": [ + ], + "environment": { + "hideHiddenFiles": true, + "uilayout": "editor-terminal", + "uisettings": "java", + "uieditorpath": "/root/example/ognl-demo" + }, + "backend": { + "imageid": "openjdk:15" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-cn/intro.md b/tutorials/katacoda/case-ognl-practise-cn/intro.md new file mode 100644 index 000000000..bb91575d0 --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-cn/intro.md @@ -0,0 +1,9 @@ +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。 + + +本教程会以一个简单的应用为例,演示如果调试`ognl`表达式。 + +* Github: https://github.com/alibaba/arthas +* 文档: https://arthas.aliyun.com/doc/ \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-cn/setup.sh b/tutorials/katacoda/case-ognl-practise-cn/setup.sh new file mode 100644 index 000000000..043faca1d --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-cn/setup.sh @@ -0,0 +1 @@ +mkdir -p example; cd example/; git clone https://github.com/hengyunabc/ognl-demo.git ; cd ognl-demo \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-cn/step1.md b/tutorials/katacoda/case-ognl-practise-cn/step1.md new file mode 100644 index 000000000..c9267738e --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-cn/step1.md @@ -0,0 +1,84 @@ + +演示Arthas里`watch`命令中`ognl`表达式的工作流程。用户可以自己修改`Demo.java`里的表达式,再执行验证。 + +项目地址: https://github.com/hengyunabc/ognl-demo +# 打开Demo.java文件 + +`src/main/java/com/example/ognl/Demo.java`{{open}} + +# 编译运行代码 + +`mvn compile exec:java`{{execute}} + + +输出结果包含`ognl`表达式输出结果: + +```java +AtEnter, conditionExpress: params[0] > 1, conditionResult: true +@ArrayList[ + @TestService[ + ], + @Object[][ + @Integer[1000], + @String[hello], + @Student[ + id=@Long[1], + name=@String[tom], + ], + ], +] +``` + + +以上输出结果,对应在代码里的表达式是: + +```java +String watchExpress = "{target, params, returnObj, #cost}"; +String conditionExpress = "params[0] > 1 && #cost > 0.1"; +``` + +类似在arthas里执行下面的`watch`命令: + +```bash +watch com.example.ognl.TestService test "{target, params, returnObj, #cost}" "params[0] > 1 && #cost > 0.1" -x 3 +``` + +# 查看函数抛出异常时的表达式结果 + +`mvn compile exec:java -DexceptionCase=true`{{execute}} + + +The output: + +```java +AtExceptionExit, conditionExpress: params[0] > 1, conditionResult: true +@ArrayList[ + @TestService[ + ], + @Object[][ + @Integer[1000], + @String[hello], + @Student[com.example.ognl.Student@6e23bcdd], + ], + java.lang.IllegalArgumentException: error + at com.example.ognl.TestService.test(TestService.java:12) + at com.example.ognl.Demo.test(Demo.java:43) + at com.example.ognl.Demo.main(Demo.java:20) + at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254) + at java.base/java.lang.Thread.run(Thread.java:832) +, +] +``` + +代码里的表达式: + +```java +String watchExpress = "{target, params, throwExp}"; +String conditionExpress = "params[0] > 1"; +``` + +类似在arthas里执行下面的`watch`命令: + +```bash +watch com.example.ognl.TestService test "{target, params, throwExp}" "params[0] > 1" -e -x 2 +``` diff --git a/tutorials/katacoda/case-ognl-practise-en/finish.md b/tutorials/katacoda/case-ognl-practise-en/finish.md new file mode 100644 index 000000000..b9f86b13c --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-en/finish.md @@ -0,0 +1,12 @@ +The tutorial demonstrates how to debug `ognl` express in Arthas. If you have more tips or questions, please feel free to tell or ask in Issue. + +* For special usage of OGNL, please refer to: https://github.com/alibaba/arthas/issues/71 +* Official Guide to OGNL Expressions: https://commons.apache.org/proper/commons-ognl/language-guide.html + +--- + +* Issues: https://github.com/alibaba/arthas/issues +* Documentation: https://arthas.aliyun.com/doc/en + +If you are using Arthas, please let us know that. Your use is very important to us: [View](https://github.com/alibaba/arthas/issues/111) + diff --git a/tutorials/katacoda/case-ognl-practise-en/index.json b/tutorials/katacoda/case-ognl-practise-en/index.json new file mode 100644 index 000000000..04402c2bf --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-en/index.json @@ -0,0 +1,29 @@ +{ + "title": "Debug ognl express in Arthas", + "description": "Debug ognl express in Arthas", + "details": { + "steps": [ + { + "text": "step1.md", + "code": "setup.sh" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + } + }, + "files": [ + ], + "environment": { + "hideHiddenFiles": true, + "uilayout": "editor-terminal", + "uisettings": "java", + "uieditorpath": "/root/example/ognl-demo" + }, + "backend": { + "imageid": "openjdk:15" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-en/intro.md b/tutorials/katacoda/case-ognl-practise-en/intro.md new file mode 100644 index 000000000..2415e33ae --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-en/intro.md @@ -0,0 +1,8 @@ +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers. + +This tutorial show how to debug `ognl` express in Arths. + +* Github: https://github.com/alibaba/arthas +* Docs: https://arthas.aliyun.com/doc/en \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-en/setup.sh b/tutorials/katacoda/case-ognl-practise-en/setup.sh new file mode 100644 index 000000000..043faca1d --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-en/setup.sh @@ -0,0 +1 @@ +mkdir -p example; cd example/; git clone https://github.com/hengyunabc/ognl-demo.git ; cd ognl-demo \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-practise-en/step1.md b/tutorials/katacoda/case-ognl-practise-en/step1.md new file mode 100644 index 000000000..6cea0e04f --- /dev/null +++ b/tutorials/katacoda/case-ognl-practise-en/step1.md @@ -0,0 +1,85 @@ + +Demonstrate the workflow of the `ognl` expression in the `watch` command in Arthas. You can modify the expressions in `Demo.java`, and compile and run the code. + +Project: https://github.com/hengyunabc/ognl-demo + +# Open the Demo.java file + +`src/main/java/com/example/ognl/Demo.java`{{open}} + +# Compile and run the code + +`mvn compile exec:java`{{execute}} + + +输出结果包含`ognl`表达式输出结果: + +```java +AtEnter, conditionExpress: params[0] > 1, conditionResult: true +@ArrayList[ + @TestService[ + ], + @Object[][ + @Integer[1000], + @String[hello], + @Student[ + id=@Long[1], + name=@String[tom], + ], + ], +] +``` + + +Expression in the code: + +```java +String watchExpress = "{target, params, returnObj, #cost}"; +String conditionExpress = "params[0] > 1 && #cost > 0.1"; +``` + +The result is similar to the following expression: + +```bash +watch com.example.ognl.TestService test "{target, params, returnObj, #cost}" "params[0] > 1 && #cost > 0.1" -x 3 +``` + +# View the expression result when the method throws an exception + +`mvn compile exec:java -DexceptionCase=true`{{execute}} + + +The output: + +```java +AtExceptionExit, conditionExpress: params[0] > 1, conditionResult: true +@ArrayList[ + @TestService[ + ], + @Object[][ + @Integer[1000], + @String[hello], + @Student[com.example.ognl.Student@6e23bcdd], + ], + java.lang.IllegalArgumentException: error + at com.example.ognl.TestService.test(TestService.java:12) + at com.example.ognl.Demo.test(Demo.java:43) + at com.example.ognl.Demo.main(Demo.java:20) + at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254) + at java.base/java.lang.Thread.run(Thread.java:832) +, +] +``` + +Expression in the code: + +```java +String watchExpress = "{target, params, throwExp}"; +String conditionExpress = "params[0] > 1"; +``` + +The result is similar to the following expression: + +```bash +watch com.example.ognl.TestService test "{target, params, throwExp}" "params[0] > 1" -e -x 2 +``` diff --git a/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json b/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json index 1c0078bd7..09c546458 100644 --- a/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json +++ b/tutorials/katacoda/case-ognl-update-logger-level-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-ognl-update-logger-level-en/index.json b/tutorials/katacoda/case-ognl-update-logger-level-en/index.json index f6389e34a..d9c13e5ed 100644 --- a/tutorials/katacoda/case-ognl-update-logger-level-en/index.json +++ b/tutorials/katacoda/case-ognl-update-logger-level-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-save-log-cn/arthas-demo.md b/tutorials/katacoda/case-save-log-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/case-save-log-cn/arthas-demo.md +++ b/tutorials/katacoda/case-save-log-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/case-save-log-cn/index.json b/tutorials/katacoda/case-save-log-cn/index.json index 17af6b629..966ef323e 100644 --- a/tutorials/katacoda/case-save-log-cn/index.json +++ b/tutorials/katacoda/case-save-log-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-save-log-en/arthas-demo.md b/tutorials/katacoda/case-save-log-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/case-save-log-en/arthas-demo.md +++ b/tutorials/katacoda/case-save-log-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/case-save-log-en/index.json b/tutorials/katacoda/case-save-log-en/index.json index f59d96a06..227325fa4 100644 --- a/tutorials/katacoda/case-save-log-en/index.json +++ b/tutorials/katacoda/case-save-log-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-thread-cn/arthas-demo.md b/tutorials/katacoda/case-thread-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/case-thread-cn/arthas-demo.md +++ b/tutorials/katacoda/case-thread-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/case-thread-cn/index.json b/tutorials/katacoda/case-thread-cn/index.json index 734a54a27..045378ca5 100644 --- a/tutorials/katacoda/case-thread-cn/index.json +++ b/tutorials/katacoda/case-thread-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-thread-en/arthas-demo.md b/tutorials/katacoda/case-thread-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/case-thread-en/arthas-demo.md +++ b/tutorials/katacoda/case-thread-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/case-thread-en/index.json b/tutorials/katacoda/case-thread-en/index.json index 0e2f0f9a1..2b497bf76 100644 --- a/tutorials/katacoda/case-thread-en/index.json +++ b/tutorials/katacoda/case-thread-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-watch-method-exception-cn/index.json b/tutorials/katacoda/case-watch-method-exception-cn/index.json index 4813ca0cb..a03dde8e4 100644 --- a/tutorials/katacoda/case-watch-method-exception-cn/index.json +++ b/tutorials/katacoda/case-watch-method-exception-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-watch-method-exception-en/index.json b/tutorials/katacoda/case-watch-method-exception-en/index.json index 51b1a1946..3d4824dbe 100644 --- a/tutorials/katacoda/case-watch-method-exception-en/index.json +++ b/tutorials/katacoda/case-watch-method-exception-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-web-console-cn/arthas-demo.md b/tutorials/katacoda/case-web-console-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/case-web-console-cn/arthas-demo.md +++ b/tutorials/katacoda/case-web-console-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/case-web-console-cn/index.json b/tutorials/katacoda/case-web-console-cn/index.json index 534d8575d..9b689e30f 100644 --- a/tutorials/katacoda/case-web-console-cn/index.json +++ b/tutorials/katacoda/case-web-console-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/case-web-console-en/arthas-demo.md b/tutorials/katacoda/case-web-console-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/case-web-console-en/arthas-demo.md +++ b/tutorials/katacoda/case-web-console-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/case-web-console-en/index.json b/tutorials/katacoda/case-web-console-en/index.json index 672c8e925..b19120be9 100644 --- a/tutorials/katacoda/case-web-console-en/index.json +++ b/tutorials/katacoda/case-web-console-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-cat-cn/arthas-demo.md b/tutorials/katacoda/command-cat-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-cat-cn/arthas-demo.md +++ b/tutorials/katacoda/command-cat-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-cat-cn/index.json b/tutorials/katacoda/command-cat-cn/index.json index 149199149..871d56b24 100644 --- a/tutorials/katacoda/command-cat-cn/index.json +++ b/tutorials/katacoda/command-cat-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-cat-en/arthas-demo.md b/tutorials/katacoda/command-cat-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-cat-en/arthas-demo.md +++ b/tutorials/katacoda/command-cat-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-cat-en/index.json b/tutorials/katacoda/command-cat-en/index.json index 34f3b9ae2..5772d575e 100644 --- a/tutorials/katacoda/command-cat-en/index.json +++ b/tutorials/katacoda/command-cat-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-classloader-cn/index.json b/tutorials/katacoda/command-classloader-cn/index.json index c47ca7b2b..b7a6e4ac4 100644 --- a/tutorials/katacoda/command-classloader-cn/index.json +++ b/tutorials/katacoda/command-classloader-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "启动demo", + "title": "启动math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-classloader-en/index.json b/tutorials/katacoda/command-classloader-en/index.json index c037687f7..9cac1837b 100644 --- a/tutorials/katacoda/command-classloader-en/index.json +++ b/tutorials/katacoda/command-classloader-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-cls-cn/arthas-demo.md b/tutorials/katacoda/command-cls-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-cls-cn/arthas-demo.md +++ b/tutorials/katacoda/command-cls-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-cls-cn/index.json b/tutorials/katacoda/command-cls-cn/index.json index 77cfe1bac..57c03b438 100644 --- a/tutorials/katacoda/command-cls-cn/index.json +++ b/tutorials/katacoda/command-cls-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-cls-en/arthas-demo.md b/tutorials/katacoda/command-cls-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-cls-en/arthas-demo.md +++ b/tutorials/katacoda/command-cls-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-cls-en/index.json b/tutorials/katacoda/command-cls-en/index.json index 3900ecb91..959651d48 100644 --- a/tutorials/katacoda/command-cls-en/index.json +++ b/tutorials/katacoda/command-cls-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-dashboard-cn/arthas-demo.md b/tutorials/katacoda/command-dashboard-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-dashboard-cn/arthas-demo.md +++ b/tutorials/katacoda/command-dashboard-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-dashboard-cn/index.json b/tutorials/katacoda/command-dashboard-cn/index.json index b8900160d..6413bd655 100644 --- a/tutorials/katacoda/command-dashboard-cn/index.json +++ b/tutorials/katacoda/command-dashboard-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -31,7 +31,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-dashboard-en/arthas-demo.md b/tutorials/katacoda/command-dashboard-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-dashboard-en/arthas-demo.md +++ b/tutorials/katacoda/command-dashboard-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-dashboard-en/index.json b/tutorials/katacoda/command-dashboard-en/index.json index 3956211f0..5c9f6a323 100644 --- a/tutorials/katacoda/command-dashboard-en/index.json +++ b/tutorials/katacoda/command-dashboard-en/index.json @@ -31,7 +31,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-dump-cn/arthas-demo.md b/tutorials/katacoda/command-dump-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-dump-cn/arthas-demo.md +++ b/tutorials/katacoda/command-dump-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-dump-cn/index.json b/tutorials/katacoda/command-dump-cn/index.json index b8091e9a3..e978c1b9e 100644 --- a/tutorials/katacoda/command-dump-cn/index.json +++ b/tutorials/katacoda/command-dump-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-dump-en/arthas-demo.md b/tutorials/katacoda/command-dump-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-dump-en/arthas-demo.md +++ b/tutorials/katacoda/command-dump-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-dump-en/index.json b/tutorials/katacoda/command-dump-en/index.json index ce2f8e5c2..45d5e68d4 100644 --- a/tutorials/katacoda/command-dump-en/index.json +++ b/tutorials/katacoda/command-dump-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-echo-cn/arthas-demo.md b/tutorials/katacoda/command-echo-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-echo-cn/arthas-demo.md +++ b/tutorials/katacoda/command-echo-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-echo-cn/index.json b/tutorials/katacoda/command-echo-cn/index.json index 2ffc9f507..f81c7be11 100644 --- a/tutorials/katacoda/command-echo-cn/index.json +++ b/tutorials/katacoda/command-echo-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-echo-en/arthas-demo.md b/tutorials/katacoda/command-echo-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-echo-en/arthas-demo.md +++ b/tutorials/katacoda/command-echo-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-echo-en/index.json b/tutorials/katacoda/command-echo-en/index.json index ea91bdc82..1029e49e0 100644 --- a/tutorials/katacoda/command-echo-en/index.json +++ b/tutorials/katacoda/command-echo-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-getstatic-cn/arthas-demo.md b/tutorials/katacoda/command-getstatic-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-getstatic-cn/arthas-demo.md +++ b/tutorials/katacoda/command-getstatic-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-getstatic-cn/index.json b/tutorials/katacoda/command-getstatic-cn/index.json index 44d02f852..4b5aabebc 100644 --- a/tutorials/katacoda/command-getstatic-cn/index.json +++ b/tutorials/katacoda/command-getstatic-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-getstatic-en/arthas-demo.md b/tutorials/katacoda/command-getstatic-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-getstatic-en/arthas-demo.md +++ b/tutorials/katacoda/command-getstatic-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-getstatic-en/index.json b/tutorials/katacoda/command-getstatic-en/index.json index 1a1f7b3f9..ee9d517ea 100644 --- a/tutorials/katacoda/command-getstatic-en/index.json +++ b/tutorials/katacoda/command-getstatic-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-grep-cn/arthas-demo.md b/tutorials/katacoda/command-grep-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-grep-cn/arthas-demo.md +++ b/tutorials/katacoda/command-grep-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-grep-cn/index.json b/tutorials/katacoda/command-grep-cn/index.json index 3dc63ef48..8f95d971c 100644 --- a/tutorials/katacoda/command-grep-cn/index.json +++ b/tutorials/katacoda/command-grep-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-grep-en/arthas-demo.md b/tutorials/katacoda/command-grep-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-grep-en/arthas-demo.md +++ b/tutorials/katacoda/command-grep-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-grep-en/index.json b/tutorials/katacoda/command-grep-en/index.json index bec616273..8b343a756 100644 --- a/tutorials/katacoda/command-grep-en/index.json +++ b/tutorials/katacoda/command-grep-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-heapdump-cn/arthas-demo.md b/tutorials/katacoda/command-heapdump-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-heapdump-cn/arthas-demo.md +++ b/tutorials/katacoda/command-heapdump-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-heapdump-cn/index.json b/tutorials/katacoda/command-heapdump-cn/index.json index aff1d5822..45689308d 100644 --- a/tutorials/katacoda/command-heapdump-cn/index.json +++ b/tutorials/katacoda/command-heapdump-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-heapdump-en/arthas-demo.md b/tutorials/katacoda/command-heapdump-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-heapdump-en/arthas-demo.md +++ b/tutorials/katacoda/command-heapdump-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-heapdump-en/index.json b/tutorials/katacoda/command-heapdump-en/index.json index 7abb7bc78..1f9a3efe7 100644 --- a/tutorials/katacoda/command-heapdump-en/index.json +++ b/tutorials/katacoda/command-heapdump-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-help-cn/arthas-demo.md b/tutorials/katacoda/command-help-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-help-cn/arthas-demo.md +++ b/tutorials/katacoda/command-help-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-help-cn/index.json b/tutorials/katacoda/command-help-cn/index.json index e70c2754b..53ff370b3 100644 --- a/tutorials/katacoda/command-help-cn/index.json +++ b/tutorials/katacoda/command-help-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -31,7 +31,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-help-en/arthas-demo.md b/tutorials/katacoda/command-help-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-help-en/arthas-demo.md +++ b/tutorials/katacoda/command-help-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-help-en/index.json b/tutorials/katacoda/command-help-en/index.json index a8da89b6e..6a6226ad0 100644 --- a/tutorials/katacoda/command-help-en/index.json +++ b/tutorials/katacoda/command-help-en/index.json @@ -31,7 +31,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-history-cn/arthas-demo.md b/tutorials/katacoda/command-history-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-history-cn/arthas-demo.md +++ b/tutorials/katacoda/command-history-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-history-cn/index.json b/tutorials/katacoda/command-history-cn/index.json index fb9cb1cc9..5e713ad44 100644 --- a/tutorials/katacoda/command-history-cn/index.json +++ b/tutorials/katacoda/command-history-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-history-en/arthas-demo.md b/tutorials/katacoda/command-history-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-history-en/arthas-demo.md +++ b/tutorials/katacoda/command-history-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-history-en/index.json b/tutorials/katacoda/command-history-en/index.json index 6cacf5025..049e581a0 100644 --- a/tutorials/katacoda/command-history-en/index.json +++ b/tutorials/katacoda/command-history-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-jad-cn/arthas-demo.md b/tutorials/katacoda/command-jad-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-jad-cn/arthas-demo.md +++ b/tutorials/katacoda/command-jad-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-jad-cn/index.json b/tutorials/katacoda/command-jad-cn/index.json index 97a490a68..6ec26f937 100644 --- a/tutorials/katacoda/command-jad-cn/index.json +++ b/tutorials/katacoda/command-jad-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-jad-en/arthas-demo.md b/tutorials/katacoda/command-jad-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-jad-en/arthas-demo.md +++ b/tutorials/katacoda/command-jad-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-jad-en/index.json b/tutorials/katacoda/command-jad-en/index.json index b30b86af3..c4b271833 100644 --- a/tutorials/katacoda/command-jad-en/index.json +++ b/tutorials/katacoda/command-jad-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-jvm-cn/arthas-demo.md b/tutorials/katacoda/command-jvm-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-jvm-cn/arthas-demo.md +++ b/tutorials/katacoda/command-jvm-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-jvm-cn/index.json b/tutorials/katacoda/command-jvm-cn/index.json index acb1c12d7..333ebf3cf 100644 --- a/tutorials/katacoda/command-jvm-cn/index.json +++ b/tutorials/katacoda/command-jvm-cn/index.json @@ -37,7 +37,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-jvm-cn/jvm.md b/tutorials/katacoda/command-jvm-cn/jvm.md index 0bf1ae17e..45a29c818 100644 --- a/tutorials/katacoda/command-jvm-cn/jvm.md +++ b/tutorials/katacoda/command-jvm-cn/jvm.md @@ -7,7 +7,7 @@ ```bash [arthas@41064]$ jvm | grep PATH - CLASS-PATH packaging/target/arthas-bin/arthas-demo.jar + CLASS-PATH packaging/target/arthas-bin/math-game.jar BOOT-CLASS-PATH /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/resources.jar:/Librar LIBRARY-PATH /Users/gongdewei/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extens ``` diff --git a/tutorials/katacoda/command-jvm-en/arthas-demo.md b/tutorials/katacoda/command-jvm-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-jvm-en/arthas-demo.md +++ b/tutorials/katacoda/command-jvm-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-jvm-en/index.json b/tutorials/katacoda/command-jvm-en/index.json index 893c08508..b5c9bac2a 100644 --- a/tutorials/katacoda/command-jvm-en/index.json +++ b/tutorials/katacoda/command-jvm-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-jvm-en/jvm.md b/tutorials/katacoda/command-jvm-en/jvm.md index 17b67c38d..4600a8600 100644 --- a/tutorials/katacoda/command-jvm-en/jvm.md +++ b/tutorials/katacoda/command-jvm-en/jvm.md @@ -7,7 +7,7 @@ The `jvm`{{execute T2}} command allows you to check the current JVM’s info. ```bash [arthas@41064]$ jvm | grep PATH - CLASS-PATH packaging/target/arthas-bin/arthas-demo.jar + CLASS-PATH packaging/target/arthas-bin/math-game.jar BOOT-CLASS-PATH /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/resources.jar:/Librar LIBRARY-PATH /Users/gongdewei/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extens ``` diff --git a/tutorials/katacoda/command-keymap-cn/arthas-demo.md b/tutorials/katacoda/command-keymap-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-keymap-cn/arthas-demo.md +++ b/tutorials/katacoda/command-keymap-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-keymap-cn/index.json b/tutorials/katacoda/command-keymap-cn/index.json index c4c181ec8..98c94eeb6 100644 --- a/tutorials/katacoda/command-keymap-cn/index.json +++ b/tutorials/katacoda/command-keymap-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -39,7 +39,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-keymap-en/arthas-demo.md b/tutorials/katacoda/command-keymap-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-keymap-en/arthas-demo.md +++ b/tutorials/katacoda/command-keymap-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-keymap-en/index.json b/tutorials/katacoda/command-keymap-en/index.json index 6f8400ea4..792ef7987 100644 --- a/tutorials/katacoda/command-keymap-en/index.json +++ b/tutorials/katacoda/command-keymap-en/index.json @@ -39,7 +39,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-logger-cn/index.json b/tutorials/katacoda/command-logger-cn/index.json index 3481afb75..4fa37e489 100644 --- a/tutorials/katacoda/command-logger-cn/index.json +++ b/tutorials/katacoda/command-logger-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "启动demo", + "title": "启动math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-logger-en/index.json b/tutorials/katacoda/command-logger-en/index.json index 7739c615e..5e8022520 100644 --- a/tutorials/katacoda/command-logger-en/index.json +++ b/tutorials/katacoda/command-logger-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -39,7 +39,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-mbean-cn/arthas-demo.md b/tutorials/katacoda/command-mbean-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-mbean-cn/arthas-demo.md +++ b/tutorials/katacoda/command-mbean-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-mbean-cn/index.json b/tutorials/katacoda/command-mbean-cn/index.json index afe34b9bc..b5da48db2 100644 --- a/tutorials/katacoda/command-mbean-cn/index.json +++ b/tutorials/katacoda/command-mbean-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-mbean-en/arthas-demo.md b/tutorials/katacoda/command-mbean-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-mbean-en/arthas-demo.md +++ b/tutorials/katacoda/command-mbean-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-mbean-en/index.json b/tutorials/katacoda/command-mbean-en/index.json index bb379d4ca..53972d90a 100644 --- a/tutorials/katacoda/command-mbean-en/index.json +++ b/tutorials/katacoda/command-mbean-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-mc-redefine-cn/index.json b/tutorials/katacoda/command-mc-redefine-cn/index.json index 432cbbd12..fc14589e2 100644 --- a/tutorials/katacoda/command-mc-redefine-cn/index.json +++ b/tutorials/katacoda/command-mc-redefine-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "启动demo", + "title": "启动math-game", "text": "start-demo.md" }, { @@ -47,7 +47,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-mc-redefine-en/index.json b/tutorials/katacoda/command-mc-redefine-en/index.json index ce613f5f3..8df2ad258 100644 --- a/tutorials/katacoda/command-mc-redefine-en/index.json +++ b/tutorials/katacoda/command-mc-redefine-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -47,7 +47,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-mc-retransform-cn/arthas-boot.md b/tutorials/katacoda/command-mc-retransform-cn/arthas-boot.md new file mode 100644 index 000000000..da13e133e --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动: + +`wget https://arthas.aliyun.com/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot`是`Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。 + +选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`: + +Attach成功之后,会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。 + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/command-mc-retransform-cn/case-jad-mc-retransform.md b/tutorials/katacoda/command-mc-retransform-cn/case-jad-mc-retransform.md new file mode 100644 index 000000000..680fe27a7 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/case-jad-mc-retransform.md @@ -0,0 +1,95 @@ +下面介绍通过`jad`/`mc`/`retransform` 命令实现动态更新代码的功能。 + +目前,访问 http://localhost/user/0 ,会返回500异常: + +`curl http://localhost/user/0`{{execute T3}} + +``` +{"timestamp":1550223186170,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalArgumentException","message":"id < 1","path":"/user/0"} +``` + +下面通过热更新代码,修改这个逻辑。 + +### jad反编译UserController + +`jad --source-only com.example.demo.arthas.user.UserController > /tmp/UserController.java`{{execute T2}} + +jad反编译的结果保存在 `/tmp/UserController.java`文件里了。 + +再打开一个`Terminal 3`,然后用vim来编辑`/tmp/UserController.java`: + +`vim /tmp/UserController.java`{{execute T3}} + +比如当 user id 小于1时,也正常返回,不抛出异常: + +```java + @GetMapping(value={"/user/{id}"}) + public User findUserById(@PathVariable Integer id) { + logger.info("id: {}", (Object)id); + if (id != null && id < 1) { + return new User(id, "name" + id); + // throw new IllegalArgumentException("id < 1"); + } + return new User(id.intValue(), "name" + id); + } +``` + +### sc查找加载UserController的ClassLoader + +`sc -d *UserController | grep classLoaderHash`{{execute T2}} + +```bash +$ sc -d *UserController | grep classLoaderHash + classLoaderHash 1be6f5c3 +``` + +可以发现是 spring boot `LaunchedURLClassLoader@1be6f5c3` 加载的。 + +注意hashcode是变化的,需要先查看当前的ClassLoader信息,提取对应ClassLoader的hashcode。 + +如果你使用`-c`,你需要手动输入hashcode:`-c ` + +对于只有唯一实例的ClassLoader可以通过`--classLoaderClass`指定class name,使用起来更加方便. + +`--classLoaderClass` 的值是ClassLoader的类名,只有匹配到唯一的ClassLoader实例时才能工作,目的是方便输入通用命令,而`-c `是动态变化的。 + +### mc + +保存好`/tmp/UserController.java`之后,使用`mc`(Memory Compiler)命令来编译,并且通过`--classLoaderClass`参数指定ClassLoader: + +`mc --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader /tmp/UserController.java -d /tmp`{{execute T2}} + +```bash +$ mc --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader /tmp/UserController.java -d /tmp +Memory compiler output: +/tmp/com/example/demo/arthas/user/UserController.class +Affect(row-cnt:1) cost in 346 ms +``` + +也可以通过`mc -c /tmp/UserController.java -d /tmp`,使用`-c`参数指定ClassLoaderHash: + +```bash +$ mc -c 1be6f5c3 /tmp/UserController.java -d /tmp +``` + +### retransform + +再使用`retransform`命令重新加载新编译好的`UserController.class`: + +`retransform /tmp/com/example/demo/arthas/user/UserController.class`{{execute T2}} + +``` +$ retransform /tmp/com/example/demo/arthas/user/UserController.class +retransform success, size: 1 +``` + +### 热修改代码结果 + +`retransform`成功之后,再次访问 https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/0 ,结果是: + +``` +{ + "id": 0, + "name": "name0" +} +``` diff --git a/tutorials/katacoda/command-mc-retransform-cn/finish.md b/tutorials/katacoda/command-mc-retransform-cn/finish.md new file mode 100644 index 000000000..819e8cd4d --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/finish.md @@ -0,0 +1,11 @@ + +在“mc-retransform”中,我们演示了了Arthas的mc-retransform命令。如果有更多的技巧或者使用疑问,欢迎在Issue里提出。 + +* Issues: https://github.com/alibaba/arthas/issues +* 文档: https://arthas.aliyun.com/doc + +如果您在使用Arthas,请让我们知道。您的使用对我们非常重要:[查看](https://github.com/alibaba/arthas/issues/111) + +欢迎关注公众号,获取Arthas项目的信息、源码分析、案例实践。 + +![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg) diff --git a/tutorials/katacoda/command-mc-retransform-cn/index.json b/tutorials/katacoda/command-mc-retransform-cn/index.json new file mode 100644 index 000000000..151263c72 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/index.json @@ -0,0 +1,57 @@ +{ + "title": "Arthas mc-retransform命令", + "description": "Arthas mc-retransform命令", + "difficulty": "精通者", + "time": "10-20 分钟", + "details": { + "steps": [ + { + "title": "启动math-game", + "text": "start-demo.md" + }, + { + "title": "启动arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "mc命令", + "text": "mc.md" + }, + { + "title": "retransform命令", + "text": "retransform.md" + }, + { + "title": "热更新代码", + "text": "case-jad-mc-retransform.md" + }, + { + "title": "retransform命令更多说明", + "text": "retransform-more.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "openjdk:15", + "environmentsprotocol": "http" + } +} diff --git a/tutorials/katacoda/command-mc-retransform-cn/intro.md b/tutorials/katacoda/command-mc-retransform-cn/intro.md new file mode 100644 index 000000000..e6e8197df --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/intro.md @@ -0,0 +1,23 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。 + +`Arthas` 支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。 + +当你遇到以下类似问题而束手无策时,Arthas可以帮助你解决: + +- 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception? +- 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了? +- 遇到问题无法在线上 debug,难道只能通过加日志再重新发布吗? +- 线上遇到某个用户的数据处理有问题,但线上同样无法 debug,线下无法重现! +- 是否有一个全局视角来查看系统的运行状况? +- 有什么办法可以监控到JVM的实时运行状态? +- 怎么快速定位应用的热点,生成火焰图? + +本教程会以一个普通的Spring Boot应用为例,演示mc-retransform命令。 + +* Github: https://github.com/alibaba/arthas +* 文档: https://arthas.aliyun.com/doc/ diff --git a/tutorials/katacoda/command-mc-retransform-cn/mc.md b/tutorials/katacoda/command-mc-retransform-cn/mc.md new file mode 100644 index 000000000..de0a45183 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/mc.md @@ -0,0 +1,7 @@ + +> Memory Compiler/内存编译器,编译`.java`文件生成`.class`。 + + +可以通过`-c`/`--classLoaderClass`参数指定classloader,`-d`参数指定输出目录 + +编译生成`.class`文件之后,可以结合`retransform`命令实现热更新代码。 diff --git a/tutorials/katacoda/command-mc-retransform-cn/retransform-more.md b/tutorials/katacoda/command-mc-retransform-cn/retransform-more.md new file mode 100644 index 000000000..0a1d61d78 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/retransform-more.md @@ -0,0 +1,62 @@ + +> 加载外部的`.class`文件,retransform jvm已加载的类。 + +参考:[Instrumentation#retransformClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses-java.lang.Class...-) + + +### 查看 retransform entry + +`retransform -l`{{execute T2}} + +```bash +$ retransform -l +Id ClassName TransformCount LoaderHash LoaderClassName +1 com.example.dem 1 null null + o.arthas.user.U + serController +``` + +* TransformCount 统计在 ClassFileTransformer#transform 函数里尝试返回 entry对应的 .class文件的次数,但并不表明transform一定成功。 + +### 删除指定 retransform entry + +`retransform -d 1`{{execute T2}} + +需要指定 id: + +```bash +retransform -d 1 +``` + +### 删除所有 retransform entry + +`retransform --deleteAll`{{execute T2}} + +```bash +retransform --deleteAll +``` + +### 显式触发 retransform + +`retransform --classPattern com.example.demo.arthas.user.UserController`{{execute T2}} + +```bash +$ retransform --classPattern com.example.demo.arthas.user.UserController +retransform success, size: 1, classes: +com.example.demo.arthas.user.UserController +``` + +> 注意:对于同一个类,当存在多个 retransform entry时,如果显式触发 retransform ,则最后添加的entry生效(id最大的)。 + +### 消除 retransform 的影响 + +如果对某个类执行 retransform 之后,想消除影响,则需要: + +* 删除这个类对应的 retransform entry +* 重新触发 retransform + +> 如果不清除掉所有的 retransform entry,并重新触发 retransform ,则arthas stop时,retransform过的类仍然生效。 + +在上面删掉 retransform entry,再显式触发 retransform之后,可以用 `jad`命令来确认之前retransform的结果已经被消除了。 + +再次访问 https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/0 ,会抛出异常。 diff --git a/tutorials/katacoda/command-mc-retransform-cn/retransform.md b/tutorials/katacoda/command-mc-retransform-cn/retransform.md new file mode 100644 index 000000000..5a75714f1 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/retransform.md @@ -0,0 +1,19 @@ + +> 加载外部的`.class`文件,retransform jvm已加载的类。 + +参考:[Instrumentation#retransformClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses-java.lang.Class...-) + + +### 参数说明 + +|参数名称|参数说明| +|---:|:---| +|[c:]|ClassLoader的hashcode| +|`[classLoaderClass:]`|指定执行表达式的 ClassLoader 的 class name| +|[p:]|外部的`.class`文件的完整路径,支持多个| + + +### retransform的限制 + +* 不允许新增加field/method +* 正在跑的函数,没有退出不能生效。 diff --git a/tutorials/katacoda/command-mc-retransform-cn/start-demo.md b/tutorials/katacoda/command-mc-retransform-cn/start-demo.md new file mode 100644 index 000000000..59be66ea6 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-cn/start-demo.md @@ -0,0 +1,14 @@ + + + + +下载`demo-arthas-spring-boot.jar`,再用`java -jar`命令启动: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot`是一个很简单的spring boot应用,源代码:[查看](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +启动之后,可以访问80端口: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/command-mc-retransform-en/arthas-boot.md b/tutorials/katacoda/command-mc-retransform-en/arthas-boot.md new file mode 100644 index 000000000..0f2cd22ac --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command: + +`wget https://arthas.aliyun.com/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed. + +Select the first process, type `1`{{execute T2}} ,then type `Enter`: + +After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help. + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/command-mc-retransform-en/case-jad-mc-retransform.md b/tutorials/katacoda/command-mc-retransform-en/case-jad-mc-retransform.md new file mode 100644 index 000000000..17f478abf --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/case-jad-mc-retransform.md @@ -0,0 +1,98 @@ +This case introduces the ability to dynamically update code via the `jad`/`mc`/`retransform` command. + +Currently, visiting http://localhost/user/0 will return a 500 error: + +`curl http://localhost/user/0`{{execute T3}} + +``` +{"timestamp":1550223186170,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalArgumentException","message":"id < 1","path":"/user/0"} +``` + +This logic will be modified by `retransform` command below. + +## Use jad command to decompile UserController + +`jad --source-only com.example.demo.arthas.user.UserController > /tmp/UserController.java`{{execute T2}} + +The result of jad command will be saved in the `/tmp/UserController.java` file. + + +Then open `Terminal 3`, use `vim` to edit `/tmp/UserController.java`: + +`vim /tmp/UserController.java`{{execute T3}} + +For example, when the user id is less than 1, it also returns normally without throwing an exception: + +```java + @GetMapping(value={"/user/{id}"}) + public User findUserById(@PathVariable Integer id) { + logger.info("id: {}", (Object)id); + if (id != null && id < 1) { + return new User(id, "name" + id); + // throw new IllegalArgumentException("id < 1"); + } + return new User(id.intValue(), "name" + id); + } +``` + +### Use sc command to find the ClassLoader that loads the UserController + +`sc -d *UserController | grep classLoaderHash`{{execute T2}} + +```bash +$ sc -d *UserController | grep classLoaderHash + classLoaderHash 1be6f5c3 +``` + +It can be found that it is loaded by spring boot `LaunchedURLClassLoader@1be6f5c3`. + +Note that the hashcode changes, you need to check the current ClassLoader information first, and extract the hashcode corresponding to the ClassLoader. + +if you use`-c`, you have to manually type hashcode by `-c `. + +For classloader with only one instance, it can be specified by `--classLoaderClass` using class name, which is more convenient to use. + +The value of `--classloaderclass` is the class name of classloader. It can only work when it matches a unique classloader instance. The purpose is to facilitate the input of general commands. However, `-c ` is dynamic. + +### mc + +After saving `/tmp/UserController.java`, compile with the `mc` (Memory Compiler) command and specify the ClassLoader with the `--classLoaderClass` option: + +`mc --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader /tmp/UserController.java -d /tmp`{{execute T2}} + +```bash +$ mc --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader /tmp/UserController.java -d /tmp +Memory compiler output: +/tmp/com/example/demo/arthas/user/UserController.class +Affect(row-cnt:1) cost in 346 ms +``` + +You can also execute `mc -c /tmp/UserController.java -d /tmp`,using `-c` to specify ClassLoaderHash: + +```bash +$ mc -c 1be6f5c3 /tmp/UserController.java -d /tmp +``` + +### retransform + +Then reload the newly compiled `UserController.class` with the `retransform` command: + +`retransform /tmp/com/example/demo/arthas/user/UserController.class`{{execute T2}} + +``` +$ retransform /tmp/com/example/demo/arthas/user/UserController.class +retransform success, size: 1 +``` + +### Check the results of the hotswap code + +After the `retransform` command is executed successfully, visit https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/0 again. + +The result is: + +``` +{ + "id": 0, + "name": "name0" +} +``` diff --git a/tutorials/katacoda/command-mc-retransform-en/finish.md b/tutorials/katacoda/command-mc-retransform-en/finish.md new file mode 100644 index 000000000..6d6586a49 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/finish.md @@ -0,0 +1,7 @@ + +The `mc-retransform Tutorial` demonstrates the usage of mc-retransform. If you have more tips or questions, please feel free to tell or ask in Issue. + +* Issues: https://github.com/alibaba/arthas/issues +* Documentation: https://arthas.aliyun.com/doc/en + +If you are using Arthas, please let us know that. Your use is very important to us: [View](https://github.com/alibaba/arthas/issues/111) diff --git a/tutorials/katacoda/command-mc-retransform-en/index.json b/tutorials/katacoda/command-mc-retransform-en/index.json new file mode 100644 index 000000000..f60f08247 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/index.json @@ -0,0 +1,57 @@ +{ + "title": "Arthas mc-retransform Command", + "description": "Arthas mc-retransform Command ", + "difficulty": "master", + "time": "10-20 minutes", + "details": { + "steps": [ + { + "title": "Start math-game", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "mc Command", + "text": "mc.md" + }, + { + "title": "retransform Command", + "text": "retransform.md" + }, + { + "title": "Hotswap Code", + "text": "case-jad-mc-retransform.md" + }, + { + "title": "More information about retransform", + "text": "retransform-more.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "openjdk:15", + "environmentsprotocol": "http" + } +} diff --git a/tutorials/katacoda/command-mc-retransform-en/intro.md b/tutorials/katacoda/command-mc-retransform-en/intro.md new file mode 100644 index 000000000..3d07b4293 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/intro.md @@ -0,0 +1,39 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers. + +`Arthas` supports JDK 6+, supports Linux/Mac/Windows. + +## Background + +Oftentimes the production system network is inaccessible from local development environment. If issues are encountered in production systems, it is impossible to use IDE to debug the application remotely. What’s even worse, debugging in production environment is unacceptable, as it will suspend all the threads, leading to services downtime. + +Developers could always try to reproduce the same issue on the test/staging environment. However, this is tricky as some issues cannot be reproduced easily in a different environment, or even disappear once restarted. + +And if you’re thinking of adding some logs to your code to help trouble-shoot the issue, you will have to go through the following lifecycle: test, staging, and then to production. Time is money! This approach is inefficient! Worse still, the issue may not be fixed since it might be irreproducible once the JVM is restarted, as described above. + +Arthas is built to solve these issues. A developer can troubleshoot production issues on the fly. No JVM restart, no additional code changes. Arthas works as an observer, that is, it will never suspend your running threads. + +## Key features + +- Check whether a class is loaded? Or where the class is loaded from? (Useful for trouble-shooting jar file conflicts) +- Decompile a class to ensure the code is running as expected. +- Check classloader statistics, e.g. the number of classloaders, the number of classes loaded per classloader, the classloader hierarchy, possible classloader leaks, etc. +- Check the method invocation details, e.g. method parameter, returned values, exceptions and etc. +- Check the stack trace of specified method invocation. This is useful when a developer wants to know the caller of the method. +- Trace the method invocation to find slow sub-invocations. +- Monitor method invocation statistics, e.g. QPS (Query Per Second), RT (Return Time), success rate and etc. +- Monitor system metrics, thread states and CPU usage, GC statistics and etc. +- Supports command line interactive mode, with auto-complete feature enabled. +- Supports telnet and WebSocket, which enables both local and remote diagnostics with command line and browsers. +- Supports profiler/Flame Graph +- Supports JDK 6+ +- Supports Linux/Mac/Windows + +This tutorial takes a normal Spring Boot application as an example to demonstrate the the usage of mc-retransform. + +* Github: https://github.com/alibaba/arthas +* Docs: https://arthas.aliyun.com/doc/en diff --git a/tutorials/katacoda/command-mc-retransform-en/mc.md b/tutorials/katacoda/command-mc-retransform-en/mc.md new file mode 100644 index 000000000..77770e474 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/mc.md @@ -0,0 +1,6 @@ + +> Memory compiler, compiles `.java` files into `.class` files in memory. + +The classloader can be specified with the `-c`/`--classLoaderClass` option, the output directory can be specified with the `-d` option. + +After compiling the `.class` file, you can use the `retransform` command to update the loaded classes in JVM. diff --git a/tutorials/katacoda/command-mc-retransform-en/retransform-more.md b/tutorials/katacoda/command-mc-retransform-en/retransform-more.md new file mode 100644 index 000000000..f1bb9cfda --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/retransform-more.md @@ -0,0 +1,64 @@ + +> Load the external `*.class` files to retransform the loaded classes in JVM. + +Reference: [Instrumentation#retransformClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses-java.lang.Class...-) + + +### View retransform entry + +`retransform -l`{{execute T2}} + +```bash +$ retransform -l +Id ClassName TransformCount LoaderHash LoaderClassName +1 com.example.dem 1 null null + o.arthas.user.U + serController +``` + +* TransformCount counts the times of attempts to return the .class file corresponding to the entry in the ClassFileTransformer#transform method, but it does not mean that the transform must be successful. + +### Delete the specified retransform entry + +`retransform -d 1`{{execute T2}} + +Need to specify id: + +```bash +retransform -d 1 +``` + +### Delete all retransform entries + +`retransform --deleteAll`{{execute T2}} + +```bash +retransform --deleteAll +``` + +### Explicitly trigger retransform + +`retransform --classPattern com.example.demo.arthas.user.UserController`{{execute T2}} + +```bash +$ retransform --classPattern com.example.demo.arthas.user.UserController +retransform success, size: 1, classes: +com.example.demo.arthas.user.UserController +``` + +> Note: For the same class, when there are multiple retransform entries, if retransform is explicitly triggered, the entry added last will take effect (the one with the largest id). + +### Eliminate the influence of retransform + +If you want to eliminate the impact after performing retransform on a class, you need to: + +* Delete the retransform entry corresponding to this class +* Re-trigger retransform + +> If you do not clear all retransform entries and trigger retransform again, the retransformed classes will still take effect when arthas stop. + + +After deleting the retransform entry above and explicitly triggering the retransform, you can use the `jad` command to confirm that the result of the previous retransform has been eliminated. + +Visit https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/user/0 again, an exception will be thrown. + diff --git a/tutorials/katacoda/command-mc-retransform-en/retransform.md b/tutorials/katacoda/command-mc-retransform-en/retransform.md new file mode 100644 index 000000000..28d6b4566 --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/retransform.md @@ -0,0 +1,18 @@ + +> Load the external `*.class` files to retransform the loaded classes in JVM. + +Reference: [Instrumentation#retransformClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#retransformClasses-java.lang.Class...-) + + +### Options + +|Name|Specification| +|---:|:---| +|`[c:]`|hashcode of the class loader| +|`[classLoaderClass:]`| The class name of the ClassLoader that executes the expression. | +|`[p:]`|absolute path of the external `*.class`, multiple paths are separated with 'space'| + +### Restrictions of the retransform command + +* New field/method is not allowed +* The function that is running, no exit can not take effect. \ No newline at end of file diff --git a/tutorials/katacoda/command-mc-retransform-en/start-demo.md b/tutorials/katacoda/command-mc-retransform-en/start-demo.md new file mode 100644 index 000000000..4915b847a --- /dev/null +++ b/tutorials/katacoda/command-mc-retransform-en/start-demo.md @@ -0,0 +1,14 @@ + + + + +Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/command-monitor-cn/arthas-demo.md b/tutorials/katacoda/command-monitor-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-monitor-cn/arthas-demo.md +++ b/tutorials/katacoda/command-monitor-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-monitor-cn/index.json b/tutorials/katacoda/command-monitor-cn/index.json index b52215bab..cc1887375 100644 --- a/tutorials/katacoda/command-monitor-cn/index.json +++ b/tutorials/katacoda/command-monitor-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-monitor-en/arthas-demo.md b/tutorials/katacoda/command-monitor-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-monitor-en/arthas-demo.md +++ b/tutorials/katacoda/command-monitor-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-monitor-en/index.json b/tutorials/katacoda/command-monitor-en/index.json index 7587859ca..8b10acfed 100644 --- a/tutorials/katacoda/command-monitor-en/index.json +++ b/tutorials/katacoda/command-monitor-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-ognl-cn/index.json b/tutorials/katacoda/command-ognl-cn/index.json index d281e5ce6..09e2c8b66 100644 --- a/tutorials/katacoda/command-ognl-cn/index.json +++ b/tutorials/katacoda/command-ognl-cn/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "启动demo", + "title": "启动math-game", "text": "start-demo.md" }, { @@ -47,7 +47,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-ognl-en/index.json b/tutorials/katacoda/command-ognl-en/index.json index f67bde9c8..6e5b82f24 100644 --- a/tutorials/katacoda/command-ognl-en/index.json +++ b/tutorials/katacoda/command-ognl-en/index.json @@ -6,7 +6,7 @@ "details": { "steps": [ { - "title": "Start demo", + "title": "Start math-game", "text": "start-demo.md" }, { @@ -47,7 +47,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-options-cn/arthas-demo.md b/tutorials/katacoda/command-options-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-options-cn/arthas-demo.md +++ b/tutorials/katacoda/command-options-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-options-cn/index.json b/tutorials/katacoda/command-options-cn/index.json index 043864fe1..4bf20face 100644 --- a/tutorials/katacoda/command-options-cn/index.json +++ b/tutorials/katacoda/command-options-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-options-en/arthas-demo.md b/tutorials/katacoda/command-options-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-options-en/arthas-demo.md +++ b/tutorials/katacoda/command-options-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-options-en/index.json b/tutorials/katacoda/command-options-en/index.json index 8d6fb23bb..f8c81473d 100644 --- a/tutorials/katacoda/command-options-en/index.json +++ b/tutorials/katacoda/command-options-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-perfcounter-cn/arthas-demo.md b/tutorials/katacoda/command-perfcounter-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-perfcounter-cn/arthas-demo.md +++ b/tutorials/katacoda/command-perfcounter-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-perfcounter-cn/index.json b/tutorials/katacoda/command-perfcounter-cn/index.json index c3e47ec96..82e52db7f 100644 --- a/tutorials/katacoda/command-perfcounter-cn/index.json +++ b/tutorials/katacoda/command-perfcounter-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-perfcounter-en/arthas-demo.md b/tutorials/katacoda/command-perfcounter-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-perfcounter-en/arthas-demo.md +++ b/tutorials/katacoda/command-perfcounter-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-perfcounter-en/index.json b/tutorials/katacoda/command-perfcounter-en/index.json index 909d27492..632009a15 100644 --- a/tutorials/katacoda/command-perfcounter-en/index.json +++ b/tutorials/katacoda/command-perfcounter-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-plaintext-cn/arthas-demo.md b/tutorials/katacoda/command-plaintext-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-plaintext-cn/arthas-demo.md +++ b/tutorials/katacoda/command-plaintext-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-plaintext-cn/index.json b/tutorials/katacoda/command-plaintext-cn/index.json index cd6e0610d..6fd9510ae 100644 --- a/tutorials/katacoda/command-plaintext-cn/index.json +++ b/tutorials/katacoda/command-plaintext-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-plaintext-en/arthas-demo.md b/tutorials/katacoda/command-plaintext-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-plaintext-en/arthas-demo.md +++ b/tutorials/katacoda/command-plaintext-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-plaintext-en/index.json b/tutorials/katacoda/command-plaintext-en/index.json index fab2c3971..590b14a33 100644 --- a/tutorials/katacoda/command-plaintext-en/index.json +++ b/tutorials/katacoda/command-plaintext-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-profiler-cn/arthas-boot.md b/tutorials/katacoda/command-profiler-cn/arthas-boot.md index da13e133e..bd42b144e 100644 --- a/tutorials/katacoda/command-profiler-cn/arthas-boot.md +++ b/tutorials/katacoda/command-profiler-cn/arthas-boot.md @@ -5,7 +5,7 @@ 在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动: `wget https://arthas.aliyun.com/arthas-boot.jar -java -jar arthas-boot.jar`{{execute T2}} +java -jar arthas-boot.jar --target-ip 0.0.0.0`{{execute T2}} `arthas-boot`是`Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。 diff --git a/tutorials/katacoda/command-profiler-cn/arthas-demo.md b/tutorials/katacoda/command-profiler-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-profiler-cn/arthas-demo.md +++ b/tutorials/katacoda/command-profiler-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-profiler-cn/index.json b/tutorials/katacoda/command-profiler-cn/index.json index 22ee0717d..d393f9087 100644 --- a/tutorials/katacoda/command-profiler-cn/index.json +++ b/tutorials/katacoda/command-profiler-cn/index.json @@ -36,7 +36,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-profiler-en/arthas-boot.md b/tutorials/katacoda/command-profiler-en/arthas-boot.md index 0f2cd22ac..1726fe727 100644 --- a/tutorials/katacoda/command-profiler-en/arthas-boot.md +++ b/tutorials/katacoda/command-profiler-en/arthas-boot.md @@ -5,7 +5,7 @@ In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command: `wget https://arthas.aliyun.com/arthas-boot.jar -java -jar arthas-boot.jar`{{execute T2}} +java -jar arthas-boot.jar --target-ip 0.0.0.0`{{execute T2}} `arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed. diff --git a/tutorials/katacoda/command-profiler-en/arthas-demo.md b/tutorials/katacoda/command-profiler-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-profiler-en/arthas-demo.md +++ b/tutorials/katacoda/command-profiler-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-profiler-en/index.json b/tutorials/katacoda/command-profiler-en/index.json index 9b2bec11c..4482398ff 100644 --- a/tutorials/katacoda/command-profiler-en/index.json +++ b/tutorials/katacoda/command-profiler-en/index.json @@ -36,7 +36,7 @@ ] }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-pwd-cn/arthas-demo.md b/tutorials/katacoda/command-pwd-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-pwd-cn/arthas-demo.md +++ b/tutorials/katacoda/command-pwd-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-pwd-cn/index.json b/tutorials/katacoda/command-pwd-cn/index.json index 3a3bb44c2..a196216a9 100644 --- a/tutorials/katacoda/command-pwd-cn/index.json +++ b/tutorials/katacoda/command-pwd-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-pwd-en/arthas-demo.md b/tutorials/katacoda/command-pwd-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-pwd-en/arthas-demo.md +++ b/tutorials/katacoda/command-pwd-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-pwd-en/index.json b/tutorials/katacoda/command-pwd-en/index.json index 415903abc..b762d4b3b 100644 --- a/tutorials/katacoda/command-pwd-en/index.json +++ b/tutorials/katacoda/command-pwd-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-quit-stop-cn/arthas-demo.md b/tutorials/katacoda/command-quit-stop-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-quit-stop-cn/arthas-demo.md +++ b/tutorials/katacoda/command-quit-stop-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-quit-stop-cn/index.json b/tutorials/katacoda/command-quit-stop-cn/index.json index fd702b8b5..f2a792077 100644 --- a/tutorials/katacoda/command-quit-stop-cn/index.json +++ b/tutorials/katacoda/command-quit-stop-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-quit-stop-en/arthas-demo.md b/tutorials/katacoda/command-quit-stop-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-quit-stop-en/arthas-demo.md +++ b/tutorials/katacoda/command-quit-stop-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-quit-stop-en/index.json b/tutorials/katacoda/command-quit-stop-en/index.json index 1c6f392a8..90d7f952e 100644 --- a/tutorials/katacoda/command-quit-stop-en/index.json +++ b/tutorials/katacoda/command-quit-stop-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-reset-cn/arthas-demo.md b/tutorials/katacoda/command-reset-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-reset-cn/arthas-demo.md +++ b/tutorials/katacoda/command-reset-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-reset-cn/index.json b/tutorials/katacoda/command-reset-cn/index.json index 50ab3d2b3..39045d047 100644 --- a/tutorials/katacoda/command-reset-cn/index.json +++ b/tutorials/katacoda/command-reset-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -39,7 +39,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-reset-en/arthas-demo.md b/tutorials/katacoda/command-reset-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-reset-en/arthas-demo.md +++ b/tutorials/katacoda/command-reset-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-reset-en/index.json b/tutorials/katacoda/command-reset-en/index.json index f142ed185..630ee62b7 100644 --- a/tutorials/katacoda/command-reset-en/index.json +++ b/tutorials/katacoda/command-reset-en/index.json @@ -39,7 +39,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-sc-cn/arthas-demo.md b/tutorials/katacoda/command-sc-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-sc-cn/arthas-demo.md +++ b/tutorials/katacoda/command-sc-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-sc-cn/index.json b/tutorials/katacoda/command-sc-cn/index.json index 2da58a1d6..dbef880b4 100644 --- a/tutorials/katacoda/command-sc-cn/index.json +++ b/tutorials/katacoda/command-sc-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-sc-cn/sc.md b/tutorials/katacoda/command-sc-cn/sc.md index d249a8ebf..4f6bfc71b 100644 --- a/tutorials/katacoda/command-sc-cn/sc.md +++ b/tutorials/katacoda/command-sc-cn/sc.md @@ -43,7 +43,7 @@ ```bash $ sc -d demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false @@ -91,7 +91,7 @@ $ sc -c 3d4eac69 -d demo* ```bash $ sc -d -f demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false diff --git a/tutorials/katacoda/command-sc-en/arthas-demo.md b/tutorials/katacoda/command-sc-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-sc-en/arthas-demo.md +++ b/tutorials/katacoda/command-sc-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-sc-en/index.json b/tutorials/katacoda/command-sc-en/index.json index 1074b9250..6f2e2a31b 100644 --- a/tutorials/katacoda/command-sc-en/index.json +++ b/tutorials/katacoda/command-sc-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-sc-en/sc.md b/tutorials/katacoda/command-sc-en/sc.md index 6e278a5fd..c12c874c7 100644 --- a/tutorials/katacoda/command-sc-en/sc.md +++ b/tutorials/katacoda/command-sc-en/sc.md @@ -39,7 +39,7 @@ ```bash $ sc -d demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false @@ -89,7 +89,7 @@ The value of `--classloaderclass` is the class name of classloader. It can only ```bash $ sc -d -f demo.MathGame class-info demo.MathGame - code-source /private/tmp/arthas-demo.jar + code-source /private/tmp/math-game.jar name demo.MathGame isInterface false isAnnotation false diff --git a/tutorials/katacoda/command-session-cn/arthas-demo.md b/tutorials/katacoda/command-session-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-session-cn/arthas-demo.md +++ b/tutorials/katacoda/command-session-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-session-cn/index.json b/tutorials/katacoda/command-session-cn/index.json index a7e9d92cd..4e87b42df 100644 --- a/tutorials/katacoda/command-session-cn/index.json +++ b/tutorials/katacoda/command-session-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-session-en/arthas-demo.md b/tutorials/katacoda/command-session-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-session-en/arthas-demo.md +++ b/tutorials/katacoda/command-session-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-session-en/index.json b/tutorials/katacoda/command-session-en/index.json index 7af5f0709..3967ff7bc 100644 --- a/tutorials/katacoda/command-session-en/index.json +++ b/tutorials/katacoda/command-session-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-sm-cn/arthas-demo.md b/tutorials/katacoda/command-sm-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-sm-cn/arthas-demo.md +++ b/tutorials/katacoda/command-sm-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-sm-cn/index.json b/tutorials/katacoda/command-sm-cn/index.json index 49852b207..becfa3d8b 100644 --- a/tutorials/katacoda/command-sm-cn/index.json +++ b/tutorials/katacoda/command-sm-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-sm-en/arthas-demo.md b/tutorials/katacoda/command-sm-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-sm-en/arthas-demo.md +++ b/tutorials/katacoda/command-sm-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-sm-en/index.json b/tutorials/katacoda/command-sm-en/index.json index 8c9bfff99..6a18074d3 100644 --- a/tutorials/katacoda/command-sm-en/index.json +++ b/tutorials/katacoda/command-sm-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-stack-cn/arthas-demo.md b/tutorials/katacoda/command-stack-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-stack-cn/arthas-demo.md +++ b/tutorials/katacoda/command-stack-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-stack-cn/index.json b/tutorials/katacoda/command-stack-cn/index.json index 44d8bf269..7697d7556 100644 --- a/tutorials/katacoda/command-stack-cn/index.json +++ b/tutorials/katacoda/command-stack-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-stack-en/arthas-demo.md b/tutorials/katacoda/command-stack-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-stack-en/arthas-demo.md +++ b/tutorials/katacoda/command-stack-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-stack-en/index.json b/tutorials/katacoda/command-stack-en/index.json index 4ae3500fe..90bd1d859 100644 --- a/tutorials/katacoda/command-stack-en/index.json +++ b/tutorials/katacoda/command-stack-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-sysenv-cn/arthas-demo.md b/tutorials/katacoda/command-sysenv-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-sysenv-cn/arthas-demo.md +++ b/tutorials/katacoda/command-sysenv-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-sysenv-cn/index.json b/tutorials/katacoda/command-sysenv-cn/index.json index f394c3a54..1f5780d47 100644 --- a/tutorials/katacoda/command-sysenv-cn/index.json +++ b/tutorials/katacoda/command-sysenv-cn/index.json @@ -45,7 +45,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-sysenv-en/arthas-demo.md b/tutorials/katacoda/command-sysenv-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-sysenv-en/arthas-demo.md +++ b/tutorials/katacoda/command-sysenv-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-sysenv-en/index.json b/tutorials/katacoda/command-sysenv-en/index.json index 18803ee36..5fc38d0b7 100644 --- a/tutorials/katacoda/command-sysenv-en/index.json +++ b/tutorials/katacoda/command-sysenv-en/index.json @@ -45,7 +45,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-sysprop-cn/arthas-demo.md b/tutorials/katacoda/command-sysprop-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-sysprop-cn/arthas-demo.md +++ b/tutorials/katacoda/command-sysprop-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-sysprop-cn/index.json b/tutorials/katacoda/command-sysprop-cn/index.json index ef66ea09f..a6e44ee30 100644 --- a/tutorials/katacoda/command-sysprop-cn/index.json +++ b/tutorials/katacoda/command-sysprop-cn/index.json @@ -49,7 +49,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-sysprop-en/arthas-demo.md b/tutorials/katacoda/command-sysprop-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-sysprop-en/arthas-demo.md +++ b/tutorials/katacoda/command-sysprop-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-sysprop-en/index.json b/tutorials/katacoda/command-sysprop-en/index.json index 546779c63..7722ac075 100644 --- a/tutorials/katacoda/command-sysprop-en/index.json +++ b/tutorials/katacoda/command-sysprop-en/index.json @@ -49,7 +49,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-tee-cn/arthas-demo.md b/tutorials/katacoda/command-tee-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-tee-cn/arthas-demo.md +++ b/tutorials/katacoda/command-tee-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-tee-cn/index.json b/tutorials/katacoda/command-tee-cn/index.json index 50ebe0458..3441ecc58 100644 --- a/tutorials/katacoda/command-tee-cn/index.json +++ b/tutorials/katacoda/command-tee-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-tee-en/arthas-demo.md b/tutorials/katacoda/command-tee-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-tee-en/arthas-demo.md +++ b/tutorials/katacoda/command-tee-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-tee-en/index.json b/tutorials/katacoda/command-tee-en/index.json index 8f5b7b187..87be49dc6 100644 --- a/tutorials/katacoda/command-tee-en/index.json +++ b/tutorials/katacoda/command-tee-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-thread-cn/arthas-demo.md b/tutorials/katacoda/command-thread-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-thread-cn/arthas-demo.md +++ b/tutorials/katacoda/command-thread-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-thread-cn/index.json b/tutorials/katacoda/command-thread-cn/index.json index a9b18a444..e2dc45e00 100644 --- a/tutorials/katacoda/command-thread-cn/index.json +++ b/tutorials/katacoda/command-thread-cn/index.json @@ -37,7 +37,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-thread-en/arthas-demo.md b/tutorials/katacoda/command-thread-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-thread-en/arthas-demo.md +++ b/tutorials/katacoda/command-thread-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-thread-en/index.json b/tutorials/katacoda/command-thread-en/index.json index b65bf56b7..735ae615c 100644 --- a/tutorials/katacoda/command-thread-en/index.json +++ b/tutorials/katacoda/command-thread-en/index.json @@ -37,7 +37,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-trace-cn/arthas-demo.md b/tutorials/katacoda/command-trace-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-trace-cn/arthas-demo.md +++ b/tutorials/katacoda/command-trace-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-trace-cn/index.json b/tutorials/katacoda/command-trace-cn/index.json index 9e0c32d29..c73032f8d 100644 --- a/tutorials/katacoda/command-trace-cn/index.json +++ b/tutorials/katacoda/command-trace-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-trace-en/arthas-demo.md b/tutorials/katacoda/command-trace-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-trace-en/arthas-demo.md +++ b/tutorials/katacoda/command-trace-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-trace-en/index.json b/tutorials/katacoda/command-trace-en/index.json index 1f7c766c9..b4b933c75 100644 --- a/tutorials/katacoda/command-trace-en/index.json +++ b/tutorials/katacoda/command-trace-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-tt-cn/arthas-demo.md b/tutorials/katacoda/command-tt-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-tt-cn/arthas-demo.md +++ b/tutorials/katacoda/command-tt-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-tt-cn/index.json b/tutorials/katacoda/command-tt-cn/index.json index 892536e15..9a819544f 100644 --- a/tutorials/katacoda/command-tt-cn/index.json +++ b/tutorials/katacoda/command-tt-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-tt-en/arthas-demo.md b/tutorials/katacoda/command-tt-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-tt-en/arthas-demo.md +++ b/tutorials/katacoda/command-tt-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-tt-en/index.json b/tutorials/katacoda/command-tt-en/index.json index 9f2874844..899ca5efc 100644 --- a/tutorials/katacoda/command-tt-en/index.json +++ b/tutorials/katacoda/command-tt-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-version-cn/arthas-demo.md b/tutorials/katacoda/command-version-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-version-cn/arthas-demo.md +++ b/tutorials/katacoda/command-version-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-version-cn/index.json b/tutorials/katacoda/command-version-cn/index.json index 38b8c08e0..f18e6853a 100644 --- a/tutorials/katacoda/command-version-cn/index.json +++ b/tutorials/katacoda/command-version-cn/index.json @@ -4,7 +4,7 @@ "details": { "steps": [ { - "title": "启动arthas-demo", + "title": "启动math-game", "text": "arthas-demo.md" }, { @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-version-en/arthas-demo.md b/tutorials/katacoda/command-version-en/arthas-demo.md index a7dc3bc7c..6f39d51cd 100644 --- a/tutorials/katacoda/command-version-en/arthas-demo.md +++ b/tutorials/katacoda/command-version-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. \ No newline at end of file diff --git a/tutorials/katacoda/command-version-en/index.json b/tutorials/katacoda/command-version-en/index.json index db4e9521b..4e5df4ef6 100644 --- a/tutorials/katacoda/command-version-en/index.json +++ b/tutorials/katacoda/command-version-en/index.json @@ -27,7 +27,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file diff --git a/tutorials/katacoda/command-vmoption-cn/arthas-demo.md b/tutorials/katacoda/command-vmoption-cn/arthas-demo.md index 59ca34b8b..a5ca0cec6 100644 --- a/tutorials/katacoda/command-vmoption-cn/arthas-demo.md +++ b/tutorials/katacoda/command-vmoption-cn/arthas-demo.md @@ -2,15 +2,15 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 为了和使用vmoption后的效果作对比,此时使用`Ctrl+c`{{execute interrupt}},程序很自然地退出。 -再次启动`arthas-demo`: +再次启动`math-game`: -`java -jar arthas-demo.jar`{{execute T1}} +`java -jar math-game.jar`{{execute T1}} diff --git a/tutorials/katacoda/command-vmoption-cn/index.json b/tutorials/katacoda/command-vmoption-cn/index.json index 5541ad86b..ed5d83daf 100644 --- a/tutorials/katacoda/command-vmoption-cn/index.json +++ b/tutorials/katacoda/command-vmoption-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-vmoption-en/arthas-demo.md b/tutorials/katacoda/command-vmoption-en/arthas-demo.md index bcbed5579..e7e10c21b 100644 --- a/tutorials/katacoda/command-vmoption-en/arthas-demo.md +++ b/tutorials/katacoda/command-vmoption-en/arthas-demo.md @@ -2,16 +2,16 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. To make a contrast with using vmoption afterwards, now we use `Ctrl+c`{{execute interrupt}} and the program exit without printing any additional infomation. -Then we start `arthas-demo` again: +Then we start `math-game` again: -`java -jar arthas-demo.jar`{{execute T1}} +`java -jar math-game.jar`{{execute T1}} diff --git a/tutorials/katacoda/command-vmoption-en/index.json b/tutorials/katacoda/command-vmoption-en/index.json index f8b72939b..324ff3fc4 100644 --- a/tutorials/katacoda/command-vmoption-en/index.json +++ b/tutorials/katacoda/command-vmoption-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-vmtool-cn/arthas-boot.md b/tutorials/katacoda/command-vmtool-cn/arthas-boot.md new file mode 100644 index 000000000..da13e133e --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动: + +`wget https://arthas.aliyun.com/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot`是`Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。 + +选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`: + +Attach成功之后,会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。 + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/command-vmtool-cn/finish.md b/tutorials/katacoda/command-vmtool-cn/finish.md new file mode 100644 index 000000000..14f8e9d36 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/finish.md @@ -0,0 +1,11 @@ + +通过本教程基本掌握了Arthas vmtool 命令。如果有更多的技巧或者使用疑问,欢迎在Issue里提出。 + +* Issues: https://github.com/alibaba/arthas/issues +* 文档: https://arthas.aliyun.com/doc + +如果您在使用Arthas,请让我们知道。您的使用对我们非常重要:[查看](https://github.com/alibaba/arthas/issues/111) + +欢迎关注公众号,获取Arthas项目的信息、源码分析、案例实践。 + +![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg) diff --git a/tutorials/katacoda/command-vmtool-cn/index.json b/tutorials/katacoda/command-vmtool-cn/index.json new file mode 100644 index 000000000..fa7fa03ca --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/index.json @@ -0,0 +1,57 @@ +{ + "title": "Arthas vmtool 命令", + "description": "Arthas vmtool 命令", + "difficulty": "精通者", + "time": "10分钟", + "details": { + "steps": [ + { + "title": "Start demo", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool-spring.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool-classloader.md" + }, + { + "title": "Arthas vmtool 命令", + "text": "vmtool-gc.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "openjdk:15", + "environmentsprotocol": "http" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-cn/intro.md b/tutorials/katacoda/command-vmtool-cn/intro.md new file mode 100644 index 000000000..d632440c1 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/intro.md @@ -0,0 +1,12 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。 + + +本教程会以一个普通的Spring Boot应用为例,演示使用`vmtool`命令从JVM内部查找对象。 + +* Github: https://github.com/alibaba/arthas +* 文档: https://arthas.aliyun.com/doc/ diff --git a/tutorials/katacoda/command-vmtool-cn/start-demo.md b/tutorials/katacoda/command-vmtool-cn/start-demo.md new file mode 100644 index 000000000..59be66ea6 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/start-demo.md @@ -0,0 +1,14 @@ + + + + +下载`demo-arthas-spring-boot.jar`,再用`java -jar`命令启动: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot`是一个很简单的spring boot应用,源代码:[查看](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +启动之后,可以访问80端口: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool-classloader.md b/tutorials/katacoda/command-vmtool-cn/vmtool-classloader.md new file mode 100644 index 000000000..5304af1f0 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool-classloader.md @@ -0,0 +1,31 @@ + + + +### 指定 classloader name + + +`vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext`{{execute T2}} + + +### 指定 classloader hash + +可以通过`sc`命令查找到加载class的 classloader。 + +```bash +$ sc -d org.springframework.context.ApplicationContext + class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext + code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/ + name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext +... + class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2 + +-sun.misc.Launcher$AppClassLoader@75b84c92 + +-sun.misc.Launcher$ExtClassLoader@4f023edb + classLoaderHash 19469ea2 +``` + +然后用`-c`/`--classloader` 参数指定: + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext +``` + diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool-gc.md b/tutorials/katacoda/command-vmtool-cn/vmtool-gc.md new file mode 100644 index 000000000..1b60289ab --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool-gc.md @@ -0,0 +1,7 @@ + +### 强制GC + + +`vmtool --action forceGc`{{execute T2}} + + diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool-spring.md b/tutorials/katacoda/command-vmtool-cn/vmtool-spring.md new file mode 100644 index 000000000..9d7d6d858 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool-spring.md @@ -0,0 +1,61 @@ +下面使用`vmtool`命令查找spring里的对象。 + +### 查找spring context + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext `{{execute T2}} + +```bash +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext +@ApplicationContext[][ + @AnnotationConfigEmbeddedWebApplicationContext[org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12028586: startup date [Thu May 13 16:08:38 UTC 2021]; root of context hierarchy], +] +``` + +### 指定返回结果展开层数 + +> `getInstances` action返回结果绑定到`instances`变量上,它是数组。 + +> 通过 `-x`/`--expand` 参数可以指定结果的展开层次,默认值是1。 + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext -x 2`{{execute T2}} + +### 执行表达式 + +> `getInstances` action返回结果绑定到`instances`变量上,它是数组。可以通过`--express`参数执行指定的表达式。 + +查找所有的spring beans名字: + + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBeanDefinitionNames()'`{{execute T2}} + + +调用`userController.findUserById(1)`函数: + + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBean("userController").findUserById(1)'`{{execute T2}} + +``` +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBean("userController").findUserById(1)' +@User[ + id=@Integer[1], + name=@String[name1], +] +``` + +### 查找所有的spring mapping对象 + + +`vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping`{{execute T2}} + +```bash +$ vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping +@HandlerMapping[][ + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5d3819c8], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@11d509ba], + @RequestMappingHandlerMapping[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@56a5f2e3], + @WelcomePageHandlerMapping[org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WelcomePageHandlerMapping@4c0a4ed3], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@51e1f8c3], + @BeanNameUrlHandlerMapping[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@68c0a39c], + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@110b768d], +] +``` diff --git a/tutorials/katacoda/command-vmtool-cn/vmtool.md b/tutorials/katacoda/command-vmtool-cn/vmtool.md new file mode 100644 index 000000000..8a3e7bb3f --- /dev/null +++ b/tutorials/katacoda/command-vmtool-cn/vmtool.md @@ -0,0 +1,37 @@ + + +下面使用`vmtool`命令查找jvm对象。 + + +### 查找jvm里的字符串对象 + +`vmtool --action getInstances --className java.lang.String`{{execute T2}} + +```bash +$ vmtool --action getInstances --className java.lang.String +@String[][ + @String[Sorry, deque too big], + @String[head=%d tail=%d capacity=%d%n], + @String[elements=%s%n], + @String[sun/nio/ch/IOVecWrapper], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[sun/nio/ch/AllocatedNativeObject], + @String[sun/nio/ch/NativeObject], + @String[sun/nio/ch/IOVecWrapper$Deallocator], + @String[Java_sun_nio_ch_FileDispatcherImpl_writev0], +] +``` + +### limit参数 + +> 通过 `--limit`参数,可以限制返回值数量,避免获取超大数据时对JVM造成压力。默认值是10。 + +所以上面的命令实际上等值于: + +```bash +vmtool --action getInstances --className java.lang.String --limit 10 +``` + +如果设置`--limit`为负数,则遍历所有对象。 + diff --git a/tutorials/katacoda/command-vmtool-en/arthas-boot.md b/tutorials/katacoda/command-vmtool-en/arthas-boot.md new file mode 100644 index 000000000..0f2cd22ac --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/arthas-boot.md @@ -0,0 +1,16 @@ + + + + +In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command: + +`wget https://arthas.aliyun.com/arthas-boot.jar +java -jar arthas-boot.jar`{{execute T2}} + +`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed. + +Select the first process, type `1`{{execute T2}} ,then type `Enter`: + +After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help. + +![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png) diff --git a/tutorials/katacoda/command-vmtool-en/finish.md b/tutorials/katacoda/command-vmtool-en/finish.md new file mode 100644 index 000000000..e95ec3feb --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/finish.md @@ -0,0 +1,7 @@ + +The `vmtool Tutorial` demonstrates the usage of `vmtool`. If you have more tips or questions, please feel free to tell or ask in Issue. + +* Issues: https://github.com/alibaba/arthas/issues +* Documentation: https://arthas.aliyun.com/doc/en + +If you are using Arthas, please let us know that. Your use is very important to us: [View](https://github.com/alibaba/arthas/issues/111) diff --git a/tutorials/katacoda/command-vmtool-en/index.json b/tutorials/katacoda/command-vmtool-en/index.json new file mode 100644 index 000000000..e314aafeb --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/index.json @@ -0,0 +1,57 @@ +{ + "title": "Arthas vmtool command", + "description": "Arthas vmtool command", + "difficulty": "master", + "time": "10 minutes", + "details": { + "steps": [ + { + "title": "Start demo", + "text": "start-demo.md" + }, + { + "title": "Start arthas-boot", + "text": "arthas-boot.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool-spring.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool-classloader.md" + }, + { + "title": "Arthas vmtool command", + "text": "vmtool-gc.md" + } + ], + "intro": { + "text": "intro.md" + }, + "finish": { + "text": "finish.md" + }, + "assets": { + "host01": [] + } + }, + "environment": { + "uilayout": "terminal", + "showdashboard": true, + "dashboards": [ + { + "name": "Web Port 80", + "port": 80 + } + ] + }, + "backend": { + "imageid": "openjdk:15", + "environmentsprotocol": "http" + } +} \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/intro.md b/tutorials/katacoda/command-vmtool-en/intro.md new file mode 100644 index 000000000..1b54d431c --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/intro.md @@ -0,0 +1,12 @@ + + + +![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png) + +`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers. + + +This tutorial takes a simple application as an example to demonstrate the the usage of `vmtool`. + +* Github: https://github.com/alibaba/arthas +* Docs: https://arthas.aliyun.com/doc/en diff --git a/tutorials/katacoda/command-vmtool-en/start-demo.md b/tutorials/katacoda/command-vmtool-en/start-demo.md new file mode 100644 index 000000000..4915b847a --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/start-demo.md @@ -0,0 +1,14 @@ + + + + +Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command: + +`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar +java -jar demo-arthas-spring-boot.jar`{{execute T1}} + +`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot) + +After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com + +![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png) \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/vmtool-classloader.md b/tutorials/katacoda/command-vmtool-en/vmtool-classloader.md new file mode 100644 index 000000000..5ae959c79 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool-classloader.md @@ -0,0 +1,25 @@ +### Specify classloader name + +`vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext`{{execute T2}} + +### Specify classloader hash + +The classloader that loads the class can be found through the `sc` command. + +```bash +$ sc -d org.springframework.context.ApplicationContext + class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext + code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/ + name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext +... + class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2 + +-sun.misc.Launcher$AppClassLoader@75b84c92 + +-sun.misc.Launcher$ExtClassLoader@4f023edb + classLoaderHash 19469ea2 +``` + +Then use the `-c`/`--classloader` parameter to specify: + +```bash +vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext +``` \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/vmtool-gc.md b/tutorials/katacoda/command-vmtool-en/vmtool-gc.md new file mode 100644 index 000000000..cd82543b5 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool-gc.md @@ -0,0 +1,4 @@ + +### forceGc + +`vmtool --action forceGc`{{execute T2}} \ No newline at end of file diff --git a/tutorials/katacoda/command-vmtool-en/vmtool-spring.md b/tutorials/katacoda/command-vmtool-en/vmtool-spring.md new file mode 100644 index 000000000..da461384c --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool-spring.md @@ -0,0 +1,57 @@ +Next, use the `vmtool` command to find objects in spring. + +### Find spring context + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext `{{execute T2}} + +```bash +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext +@ApplicationContext[][ + @AnnotationConfigEmbeddedWebApplicationContext[org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12028586: startup date [Thu May 13 16:08:38 UTC 2021]; root of context hierarchy], +] +``` + +### Specify the number of expanded layers of returned results + +> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. + +> The expansion level of the result can be specified by the `-x`/`--expand` parameter, the default value is 1. + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext -x 2`{{execute T2}} + +### Execute expression + +> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. The specified expression can be executed through the `--express` parameter. + +Find the names of all spring beans: + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBeanDefinitionNames()'`{{execute T2}} + +Call the `userController.findUserById(1)` method: + +`vmtool --action getInstances --className org.springframework.context.ApplicationContext --express 'instances[0].getBean("userController").findUserById(1)'`{{execute T2}} + +``` +$ vmtool --action getInstances --className org.springframework.context.ApplicationContext --express'instances[0].getBean("userController").findUserById(1)' +@User[ + id=@Integer[1], + name=@String[name1], +] +``` + +### Find all spring mapping objects + +`vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping`{{execute T2}} + +```bash +$ vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping +@HandlerMapping[][ + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5d3819c8], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@11d509ba], + @RequestMappingHandlerMapping[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@56a5f2e3], + @WelcomePageHandlerMapping[org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WelcomePageHandlerMapping@4c0a4ed3], + @EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@51e1f8c3], + @BeanNameUrlHandlerMapping[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@68c0a39c], + @SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@110b768d], +] +``` diff --git a/tutorials/katacoda/command-vmtool-en/vmtool.md b/tutorials/katacoda/command-vmtool-en/vmtool.md new file mode 100644 index 000000000..b5bd74b29 --- /dev/null +++ b/tutorials/katacoda/command-vmtool-en/vmtool.md @@ -0,0 +1,37 @@ + + + +Use the `vmtool` command to find the jvm object. + + +### Find string objects in jvm + +`vmtool --action getInstances --className java.lang.String`{{execute T2}} + +```bash +$ vmtool --action getInstances --className java.lang.String +@String[][ + @String[Sorry, deque too big], + @String[head=%d tail=%d capacity=%d%n], + @String[elements=%s%n], + @String[sun/nio/ch/IOVecWrapper], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791], + @String[sun/nio/ch/AllocatedNativeObject], + @String[sun/nio/ch/NativeObject], + @String[sun/nio/ch/IOVecWrapper$Deallocator], + @String[Java_sun_nio_ch_FileDispatcherImpl_writev0], +] +``` + +### limit parameter + +> Through the `--limit` parameter, you can limit the number of return values to avoid pressure on the JVM when obtaining large data. The default value is 10. + +So the above command is actually equivalent to: + +```bash +vmtool --action getInstances --className java.lang.String --limit 10 +``` + +If you set `--limit` to a negative number, all objects are traversed. diff --git a/tutorials/katacoda/command-watch-cn/arthas-demo.md b/tutorials/katacoda/command-watch-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-watch-cn/arthas-demo.md +++ b/tutorials/katacoda/command-watch-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-watch-cn/index.json b/tutorials/katacoda/command-watch-cn/index.json index ce57dfe31..2c7cfd9c5 100644 --- a/tutorials/katacoda/command-watch-cn/index.json +++ b/tutorials/katacoda/command-watch-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-watch-cn/watch.md b/tutorials/katacoda/command-watch-cn/watch.md index c218b1c20..a4030b1df 100644 --- a/tutorials/katacoda/command-watch-cn/watch.md +++ b/tutorials/katacoda/command-watch-cn/watch.md @@ -48,7 +48,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 44 ms. ts=2018-12-03 19:16:51; [cost=1.280502ms] result=@ArrayList[ @Object[][ - @Integer[535629513], + @Integer[1], ], @ArrayList[ @Integer[3], @@ -92,7 +92,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 46 ms. ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -102,7 +102,7 @@ ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ ] ts=2018-12-03 19:29:54; [cost=4.277392ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -139,7 +139,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 58 ms. ts=2018-12-03 19:34:19; [cost=0.587833ms] result=@ArrayList[ @Object[][ - @Integer[47816758], + @Integer[1], ], @MathGame[ random=@Random[ @@ -244,7 +244,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 66 ms. ts=2018-12-03 19:40:28; [cost=2112.168897ms] result=@ArrayList[ @Object[][ - @Integer[2141897465], + @Integer[1], ], @ArrayList[ @Integer[5], diff --git a/tutorials/katacoda/command-watch-en/arthas-demo.md b/tutorials/katacoda/command-watch-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-watch-en/arthas-demo.md +++ b/tutorials/katacoda/command-watch-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-watch-en/index.json b/tutorials/katacoda/command-watch-en/index.json index 79fad57f6..734b577e4 100644 --- a/tutorials/katacoda/command-watch-en/index.json +++ b/tutorials/katacoda/command-watch-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-watch-en/watch.md b/tutorials/katacoda/command-watch-en/watch.md index 782e7320b..2231879c5 100644 --- a/tutorials/katacoda/command-watch-en/watch.md +++ b/tutorials/katacoda/command-watch-en/watch.md @@ -46,7 +46,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 44 ms. ts=2018-12-03 19:16:51; [cost=1.280502ms] result=@ArrayList[ @Object[][ - @Integer[535629513], + @Integer[1], ], @ArrayList[ @Integer[3], @@ -92,7 +92,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 46 ms. ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -102,7 +102,7 @@ ts=2018-12-03 19:29:54; [cost=0.01696ms] result=@ArrayList[ ] ts=2018-12-03 19:29:54; [cost=4.277392ms] result=@ArrayList[ @Object[][ - @Integer[1544665400], + @Integer[1], ], @MathGame[ random=@Random[java.util.Random@522b408a], @@ -139,7 +139,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 58 ms. ts=2018-12-03 19:34:19; [cost=0.587833ms] result=@ArrayList[ @Object[][ - @Integer[47816758], + @Integer[1], ], @MathGame[ random=@Random[ @@ -243,7 +243,7 @@ Press Ctrl+C to abort. Affect(class-cnt:1 , method-cnt:1) cost in 66 ms. ts=2018-12-03 19:40:28; [cost=2112.168897ms] result=@ArrayList[ @Object[][ - @Integer[2141897465], + @Integer[1], ], @ArrayList[ @Integer[5], diff --git a/tutorials/katacoda/command-wc-cn/arthas-demo.md b/tutorials/katacoda/command-wc-cn/arthas-demo.md index a1624cb44..d55f26622 100644 --- a/tutorials/katacoda/command-wc-cn/arthas-demo.md +++ b/tutorials/katacoda/command-wc-cn/arthas-demo.md @@ -2,9 +2,9 @@ -下载`arthas-demo.jar`,再用`java -jar`命令启动: +下载`math-game.jar`,再用`java -jar`命令启动: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 +`math-game`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。 diff --git a/tutorials/katacoda/command-wc-cn/index.json b/tutorials/katacoda/command-wc-cn/index.json index f53fee99f..a8072fae2 100644 --- a/tutorials/katacoda/command-wc-cn/index.json +++ b/tutorials/katacoda/command-wc-cn/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-wc-cn/wc.md b/tutorials/katacoda/command-wc-cn/wc.md index cc9d2908b..efba917ba 100644 --- a/tutorials/katacoda/command-wc-cn/wc.md +++ b/tutorials/katacoda/command-wc-cn/wc.md @@ -11,7 +11,7 @@ ClassLoader: +-sun.misc.Launcher$ExtClassLoader@7a616cb1 Location: -/home/scrapbook/tutorial/arthas-demo.jar +/home/scrapbook/tutorial/math-game.jar public static void main(String[] args) throws InterruptedException { MathGame game = new MathGame(); diff --git a/tutorials/katacoda/command-wc-en/arthas-demo.md b/tutorials/katacoda/command-wc-en/arthas-demo.md index fd3eb4fb6..dcc6454ad 100644 --- a/tutorials/katacoda/command-wc-en/arthas-demo.md +++ b/tutorials/katacoda/command-wc-en/arthas-demo.md @@ -2,10 +2,10 @@ -Download `arthas-demo.jar` and start with the `java -jar` command: +Download `math-game.jar` and start with the `java -jar` command: -`wget https://arthas.aliyun.com/arthas-demo.jar -java -jar arthas-demo.jar`{{execute T1}} +`wget https://arthas.aliyun.com/math-game.jar +java -jar math-game.jar`{{execute T1}} -`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results. +`math-game` is a very simple program that randomly generates integers, performs factorization, and prints the results. If the generated random number is negative, a error message will be printed. diff --git a/tutorials/katacoda/command-wc-en/index.json b/tutorials/katacoda/command-wc-en/index.json index 8f62c9831..647b0edeb 100644 --- a/tutorials/katacoda/command-wc-en/index.json +++ b/tutorials/katacoda/command-wc-en/index.json @@ -29,7 +29,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } diff --git a/tutorials/katacoda/command-wc-en/wc.md b/tutorials/katacoda/command-wc-en/wc.md index e264b3ef1..10d579097 100644 --- a/tutorials/katacoda/command-wc-en/wc.md +++ b/tutorials/katacoda/command-wc-en/wc.md @@ -11,7 +11,7 @@ ClassLoader: +-sun.misc.Launcher$ExtClassLoader@7a616cb1 Location: -/home/scrapbook/tutorial/arthas-demo.jar +/home/scrapbook/tutorial/math-game.jar public static void main(String[] args) throws InterruptedException { MathGame game = new MathGame(); diff --git a/tutorials/katacoda/common-resources/assets/qrcode_gongzhonghao.jpg b/tutorials/katacoda/common-resources/assets/qrcode_gongzhonghao.jpg index 8fdd52b4c..9d0e54ab8 100644 Binary files a/tutorials/katacoda/common-resources/assets/qrcode_gongzhonghao.jpg and b/tutorials/katacoda/common-resources/assets/qrcode_gongzhonghao.jpg differ diff --git a/tutorials/katacoda/common-resources/finish.md b/tutorials/katacoda/common-resources/finish.md index 74041380b..7555f78ec 100644 --- a/tutorials/katacoda/common-resources/finish.md +++ b/tutorials/katacoda/common-resources/finish.md @@ -2,3 +2,8 @@ * Issues: https://github.com/alibaba/arthas/issues * 文档: https://arthas.aliyun.com/doc * Documentation: https://arthas.aliyun.com/doc/en + + +欢迎关注公众号,获取Arthas项目的信息、源码分析、案例实践。 + +![Arthas公众号](./assets/qrcode_gongzhonghao.jpg) diff --git a/tutorials/katacoda/common-resources/index.json b/tutorials/katacoda/common-resources/index.json index 1f7bf18c3..49c3e21c2 100644 --- a/tutorials/katacoda/common-resources/index.json +++ b/tutorials/katacoda/common-resources/index.json @@ -19,7 +19,7 @@ "uilayout": "terminal" }, "backend": { - "imageid": "java", + "imageid": "openjdk:15", "environmentsprotocol": "http" } } \ No newline at end of file