This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244500

Summary: Array allocations done via Array.newInstance() are sometimes not tracked
Product: profiler Reporter: Tomas Hurka <thurka>
Component: BaseAssignee: Tomas Hurka <thurka>
Status: RESOLVED FIXED    
Severity: normal Keywords: VISUALVM
Priority: P3    
Version: 8.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description Tomas Hurka 2014-05-15 07:33:07 UTC
If the array is initially allocated by Array.newInstance(), those allocations are not tracked. Once the array is allocated by ordinary new A[1] expression, subsequect allocation via Array.newInstance() are tracked. See simple test case below:

package allocref;
import java.lang.reflect.Array;

public class Allocref {

    public static void main(String[] args) {
        Allocref r = new Allocref();    
        r.test();
    }

    private void test() {
        for (int i=0; i<100; i++) {
            Allocref[] arr = (Allocref[]) Array.newInstance(Allocref.class, 1);
            arr[0] = new Allocref();
        }
    } 
}

in this example allocref.Allocref[] instances are not tracked. If the test case is changed to:

package allocref;
import java.lang.reflect.Array;

public class Allocref {

    public static void main(String[] args) {
        Allocref r = new Allocref();
        
        r.test();
    }

    private void test() {
        Allocref[] a = new Allocref[1000];
        for (int i=0; i<100; i++) {
            Allocref[] arr = (Allocref[]) Array.newInstance(Allocref.class, 1);
            arr[0] = new Allocref();
        }
    }
    
}

[note the change in the first line of the test() method]. Everything works fine and allocref.Allocref[] instances are tracked by profiler.
Comment 1 Tomas Hurka 2014-05-15 10:49:44 UTC
Fixed in profiler-main

changeset:   273718:c6bc270a3171
user:        Tomas Hurka <thurka@netbeans.org>
date:        Thu May 15 12:47:49 2014 +0200
summary:     bugfix #244500, set instrclassId for array class, but only if it is not already set
Comment 2 Quality Engineering 2014-05-15 19:36:36 UTC
Integrated into 'main-silver', will be available in build *201405151825* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/c6bc270a3171
User: Tomas Hurka <thurka@netbeans.org>
Log: bugfix #244500, set instrclassId for array class, but only if it is not already set