简体   繁体   中英

Method name triggers auto-boxing of primitives when profiling with JProfiler

I am using JProfiler 7.2.3 to profile the memory allocations in my application. I have classes with methods like set(int, double) and setDouble(int, double) . The two methods are absolutely identical, but JProfiler says that the latter method creates a boxed Double while the former method does not.

The following code demonstrates the issue. When recording memory allocations with JProfiler, there are 100,000 Double objects created in the calls to setDouble(int, double) , but no objects are created in the other identical methods. The only difference is the method name!

How can I prevent JProfiler from miscounting the number of Double objects without renaming the setDouble method? Why does JProfiler miscount the Double objects in the first place?

public final class Test {
    public static void main(String[] args) throws java.io.IOException {
        Test test = new Test();

        for (int i = 0; i < 100000; i++)
            test.set(i, i);

        for (int i = 0; i < 100000; i++)
            test.setD(i, i);

        for (int i = 0; i < 100000; i++)
            test.setDestination(i, i);

        // JProfiler says this method creates boxed Double objects
        for (int i = 0; i < 100000; i++)
            test.setDouble(i, i);

        for (int i = 0; i < 100000; i++)
            test.setDoubleValue(i, i);

        // Don't terminate VM
        System.in.read();
    }

    private double[] values = new double[100000];

    public final void set(int i, double value) {
        values[i] = value;
    }

    public final void setD(int i, double value) {
        values[i] = value;
    }

    public final void setDestination(int i, double value) {
        values[i] = value;
    }

    public final void setDouble(int i, double value) {
        values[i] = value;
    }

    public final void setDoubleValue(int i, double value) {
        values[i] = value;
    }
}

This is a side-effect of the JDBC probe. If you disable the JDBC probe, this will no longer be the case.

In JProfiler 8, the probe system has been rewritten to be more efficient and this is no longer the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM