Coder Social home page Coder Social logo

Comments (7)

DamianSheldon avatar DamianSheldon commented on July 20, 2024 1

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.

jbachorik avatar jbachorik commented on July 20, 2024

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.

jbachorik avatar jbachorik commented on July 20, 2024

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.

DamianSheldon avatar DamianSheldon commented on July 20, 2024

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.

jbachorik avatar jbachorik commented on July 20, 2024

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.

DamianSheldon avatar DamianSheldon commented on July 20, 2024

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.

github-actions avatar github-actions commented on July 20, 2024

Stale issue message

from btrace.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.