Comments (7)
The source code of the BTraceTest class:
package com.github.damiansheldon.jvm.chapter4;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BTraceTest {
public static void main(String[] args) throws Exception {
BTraceTest test = new BTraceTest();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
br.readLine();
int a = (int)Math.round(Math.random() * 1000);
int b = (int)Math.round(Math.random() * 1000);
System.out.println(test.add(a, b));
}
}
public int add(int a, int b) {
return a + b;
}
}
The source code of the trace script:
import org.openjdk.btrace.core.annotations.*;
import static org.openjdk.btrace.core.BTraceUtils.*;
@BTrace
public class TracingAddMethod {
@OnMethod(
clazz="com.github.damiansheldon.jvm.chapter4.BTraceTest",
method="add",
location=@Location(Kind.RETURN)
)
public static void func(
@Self com.github.damiansheldon.jvm.chapter4.BTraceTest instance,
int a,
int b,
@Return int result
) {
println("stacktrace...");
jstack();
println(strcat("arg a:", str(a)));
println(strcat("arg b:", str(b)));
println(strcat("result:", str(result)));
}
}
There are also three warnings output at console, full log as follow:
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
btrace WARNING: BTrace bootstrap classpath resource [ /Users/meiliang/Library/Application%20Support/VisualVM/2.1.3/modules/ext/btrace-boot.jar] does not exist
btrace WARNING: BTrace system classpath resource [/Users/meiliang/.sdkman/candidates/java/17.0.3-oracle/lib/tools.jar] does not exist.
r
[BTRACE] Failed to link probe handler: org/openjdk/btrace/runtime/auxiliary/TracingAddMethod.$btrace$org$openjdk$btrace$runtime$auxiliary$TracingAddMethod$func
java.lang.VerifyError: Stack map does not match the one at exception handler 61
Exception Details:
Location:
com/github/damiansheldon/jvm/chapter4/BTraceTest+0x0000000800d18800.func(Lcom/github/damiansheldon/jvm/chapter4/BTraceTest;III)V @61: getstatic
Reason:
Type 'com/github/damiansheldon/jvm/chapter4/BTraceTest' (current frame, locals[0]) is not assignable to 'com/github/damiansheldon/jvm/chapter4/BTraceTest+0x0000000800d18800' (stack map, locals[0])
Current Frame:
bci: @10
flags: { }
locals: { 'com/github/damiansheldon/jvm/chapter4/BTraceTest', integer, integer, integer }
stack: { 'java/lang/Throwable' }
Stackmap Frame:
bci: @61
flags: { }
locals: { 'com/github/damiansheldon/jvm/chapter4/BTraceTest+0x0000000800d18800', integer, integer, integer }
stack: { 'java/lang/Throwable' }
Bytecode:
0000000: b200 1ab8 0020 9a00 04b1 1222 b800 28b8
0000010: 002c 122e 1bb8 0032 b800 36b8 0028 1238
0000020: 1cb8 0032 b800 36b8 0028 123a 1db8 0032
0000030: b800 36b8 0028 b200 1ab6 003f b1b2 001a
0000040: 5a5f b600 43b2 001a b600 3fb1
Exception Handler Table:
bci [10, 61] => handler: 61
Stackmap Table:
same_frame(@10)
full_frame(@61,{Object[#2],Integer,Integer,Integer},{Object[#20]})
421
from btrace.
Hi, thanks for reporting this!
Would it be possible to share the source code of the BTraceTest
class?
TBH, the type descriptor com/github/damiansheldon/jvm/chapter4/BTraceTest+0x0000000800cd4800
looks rather unusual and it would be good to know what is producing such type descriptors.
from btrace.
Unfortunately, even this reproducer does not reproduce for me. I tried BTrace 2.2.2 as well as trunk build they all work fine.
Here is my env, for comparison. The only difference I see is that I am using JDK 17.0.3.1 whereas you are using 17.0.3 - but AFAICT from the JDK release notes this difference should not affect anything.
> sw_vers
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
> java -version
java version "17.0.3.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3.1+2-LTS-6, mixed mode, sharing)
Could you run this command on the trunk build of BTrace and attach here the file you should find at /tmp/btrace_test/com_github_damiansheldon_jvm_chapter4_BTraceTest.class
? That should contain the bytecode of the handler class which is giving you this error.
java -javaagent:btrace-agent.jar=dumpClasses=true,dumpDir=/tmp/btrace_test,debug=true,script=TracingAddMethod.class com.github.damiansheldon.jvm.chapter4.BTraceTest
from btrace.
It very strange, I now can successfully trace with command: java -cp bin -javaagent:/Users/meiliang/Downloads/btrace-v2.2.2/libs/btrace-agent.jar=dumpClasses=true,dumpDir=/tmp/btrace_test,debug=true,script=bin/TracingAddMethod.class com.github.damiansheldon.jvm.chapter4.BTraceTest
or btrace -cp bin <pid> bin/TracingAddMethod.class
。
But BTrace plugin in VisualVM can still reproduce this issue.
VisualVM's version is : 2.1.3 (Build 220330); platform 20220209-2172674416
。
I Start it with command: /Applications/VisualVM.app/Contents/MacOS/visualvm --jdkhome /Users/meiliang/.sdkman/candidates/java/17.0.3-oracle/
。
BTrace plugin's version is:
Version: 2.1.0 Source: org-openjdk-btrace-visualvm.nbm
Here is the
com_github_damiansheldon_jvm_chapter4_BTraceTest.class.zip
from btrace.
Well, in VisualVM is still version 2.1.0 which is rather old (working on getting the current version to VisualVM UC soon with the maintainers - but in the meantime you can download the updated plugins from https://github.com/btraceio/btrace.visualvm/releases/tag/v2.2.2 and install them manually).
The generated probe class from the archive you sent looks fine (as expected).
If the problem is not reproducible in BTrace 2.2.2 or the trunk build I would close this issue. The 2.1.0 version is pretty outdated and there will be no updates to 2.1.* line.
from btrace.
Plugin from https://github.com/btraceio/btrace.visualvm/releases/tag/v2.2.2 can reproduce this issue.
First I uninstall, then restart VisualVM to reinstall. I think this can remove previous version plugin's effect.
I realize plugin's version 2.1.0 which is BTrace Workbench's version , its base on BTrace API 2.2.0.
I think previous installed plugin already is version 2.2.0.
I also did some other experiments, after btrace plugin cause this issue, I rerun the program from eclipse, then try to trace, btrace -cp bin <pid> src/com/github/damiansheldon/jvm/chapter6/TracingAddMethod.java
will cause issue, but btrace -cp bin <pid> bin/TracingAddMethod.class
not, java -cp bin -javaagent:/Users/meiliang/Downloads/btrace-v2.2.2/libs/btrace-agent.jar=dumpClasses=trueumpDir=/tmp/btrace_test,debug=true,script=bin/TracingAddMethod.class com.github.damiansheldon.jvm.chapter4.BTraceTest
also not cause problem.
from btrace.
Stale issue message
from btrace.
Related Issues (20)
- Exception in thread "main" java.lang.NullPointerException HOT 2
- Throw NoSuchFieldException when call getInt() method HOT 5
- btrace INFO: Attaching BTrace to PID: 3866 Broken pipe HOT 1
- Does the BTrace agent support java 17? HOT 1
- Unsupported class file major version 29281 HOT 5
- Is adding method printStrings with a ... array possible? HOT 4
- Javaagent args for output directory seems wrong HOT 3
- Btrace doesn't trace methods when trusted is true HOT 1
- Adding XStream to the dependencies error HOT 2
- JAR artifacts are shadowed with the version number
- [BTRACE WARN] Class verification failed:
- Windows batch scripts do not work properly HOT 2
- Build fails with missing artifact HOT 4
- NoClassDefFoundError for NonBlockingIdentityHashMap when running an application with BTrace HOT 4
- Review target compileJava15Java in btrace-runtime/build.gradle
- NoClassDefFoundError for ConcurrentAutoTable and others when running an application with BTrace HOT 1
- VerifyError: Bad type on operand stack HOT 2
- MT-safety of HistoOnEvent example HOT 5
- The gradle-wrapper.jar is stale with respect to gradle version. HOT 1
- Does the BTrace agent support java 21? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from btrace.