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 187723 - Categorization Mark methods is stateful .
Summary: Categorization Mark methods is stateful .
Status: RESOLVED FIXED
Alias: None
Product: profiler
Classification: Unclassified
Component: Ide (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: issues@profiler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-17 12:10 UTC by Denis Anisimov
Modified: 2010-07-08 03:26 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Denis Anisimov 2010-06-17 12:10:32 UTC
There is a problem with marks which assigned to methods on Profiling 
procedure.
Methods could be marked via 
org.netbeans.lib.profiler.results.cpu.marking.MarkingEngine class method
markMethod(int methodId,... ) .
Which uses MarkMapper class: 
public Mark markMethod(int methodId, ProfilingSessionStatus status) {
        synchronized(mapper) {
            return mapper.getMark(methodId, status);
        }
    }

This is the code of MarkMapper.getMark method :

public Mark getMark(int methodId, ProfilingSessionStatus status) {
        if (status == null) {
            return Mark.DEFAULT;
        }
        
        synchronized (marksGuard) {
            Mark mark = (Mark) markMap.get(Integer.valueOf(methodId));

            if (mark == null) {
                mark = MarkingEngine.getDefault().mark(methodId, status); // do mark the method
                markMap.put(Integer.valueOf(methodId), mark);
            }

            return mark;
        }
    }

MarkingEngine  class is singleton. So each  call to its "markMethod" method
delegate to the same MarkMapper class. As result "markMap" HashMap is used 
the same.
Here is the problem : only the very first profile action uses empty MarkMapper.markMap HashMap. All subsequent "Proflile" action 
calls uses already filled map .
This can lead to unexpected result. Methods with same id ( but different 
unrelated profile session ) could be marked incorrectly ( because of non-empty
hash map ).

Solution is : MarkMapper.markMap should be cleared on each "Profiler" 
start action. There are already methods for this :
reset() which is called from stateChanged(MarkingEngine) method.
The latter method is "observer" method of interface MarkingEngine.StateObserver.
It is supposed to be called when new "Profile" action is called.
But it called for WRONG INSTANCE of MarkMapper!

MarkMapper is registered in the default lookup as MarkingEngine.StateObserver
observer for MarkingEngine  class. And it is set on "Profile" action call:
MarkingEngine.getDefault().configure(ctg.getMappings(), Lookup.getDefault().lookupAll(MarkingEngine.StateObserver.class));

As result instance WHICH IS REGISTERED IN THE DEFAULT LOOKUP will be notified
about change state for MarkingEngine.
But MarkingEngine constructor uses DIFFERENT instance of MarkMapper :
    private MarkingEngine() {
        mapper = new MarkMapper();
    }
This latter mapper instance is used for methods marking. And it's method 
stateChanged() is never called . So it keeps state over different profiler
runs.
These runs could be performed on the same project which was 
modified dramatically between profiler runs or even for different projects.
So such stateful behavior is very serious issue.
Comment 1 J Bachorik 2010-06-17 13:22:33 UTC
Yes, indeed :(
Comment 2 Denis Anisimov 2010-07-01 16:42:06 UTC
changeset:   173644:231fb0963173
user:        Denis Anisimov <ads@netbeans.org>
date:        Thu Jul 01 20:39:48 2010 +0400
summary:     Fix for IZ#187723, unit tests for J2SE project categorization feature.
Comment 3 Quality Engineering 2010-07-08 03:26:27 UTC
Integrated into 'main-golden', will be available in build *201007080001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/231fb0963173
User: Denis Anisimov <ads@netbeans.org>
Log: Fix for IZ#187723, unit tests for J2SE project categorization feature.