6604014: add support for ideal graph visualizer

Reviewed-by: kvn, jrose
This commit is contained in:
Tom Rodriguez 2008-06-23 18:21:18 -07:00
parent 5106cf17a3
commit 2d64a7a369
336 changed files with 24564 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<attr name="Actions\Edit\com-sun-hotspot-igv-bytecodes-SelectBytecodesAction.instance\position" intvalue="200"/>
<attr name="Actions\Edit\org-netbeans-core-ui-sysopen-SystemOpenAction.instance\position" intvalue="100"/>
<attr name="Actions\Edit\org-openide-actions-CopyAction.instance\position" intvalue="1300"/>
<attr name="Actions\Edit\org-openide-actions-CutAction.instance\position" intvalue="1400"/>
<attr name="Actions\Edit\org-openide-actions-DeleteAction.instance\position" intvalue="1500"/>
<attr name="Actions\Edit\org-openide-actions-FindAction.instance\position" intvalue="1600"/>
<attr name="Actions\Edit\org-openide-actions-GotoAction.instance\position" intvalue="1700"/>
<attr name="Actions\Edit\org-openide-actions-PasteAction.instance\position" intvalue="1800"/>
<attr name="Actions\Edit\org-openide-actions-RedoAction.instance\position" intvalue="1900"/>
<attr name="Actions\Edit\org-openide-actions-ReplaceAction.instance\position" intvalue="2000"/>
<attr name="Actions\Edit\org-openide-actions-UndoAction.instance\position" intvalue="2100"/>
<folder name="Actions">
<folder name="File">
<file name="com-sun-hotspot-igv-coordinator-actions-SaveAsAction.instance">
<attr name="position" intvalue="700"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-SaveAllAction.instance">
<attr name="position" intvalue="800"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-ImportAction.instance">
<attr name="position" intvalue="1000"/>
</file>
</folder>
<folder name="Edit">
<file name="com-sun-hotspot-igv-coordinator-actions-RemoveAction.instance">
<attr name="position" intvalue="1200"/>
</file>
</folder>
<folder name="Window">
<file name="com-sun-hotspot-igv-coordinator-actions-OutlineAction.instance"/>
</folder>
</folder>
<folder name="Menu">
<folder name="File">
<file name="com-sun-hotspot-igv-coordinator-actions-ImportAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-ImportAction.instance"/>
<attr name="position" intvalue="100"/>
</file>
<file name="MySeparator2.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="300"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-SaveAsAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-SaveAsAction.instance"/>
<attr name="position" intvalue="300"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-SaveAllAction.shadow">
<attr name="originalFile" stringvalue="Actions/File/com-sun-hotspot-igv-coordinator-actions-SaveAllAction.instance"/>
<attr name="position" intvalue="400"/>
</file>
<file name="MySeparator3.instance">
<attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>
<attr name="position" intvalue="500"/>
</file>
<file name="org-netbeans-modules-openfile-OpenFileAction.instance_hidden"/>
<file name="org-openide-actions-PageSetupAction.instance_hidden"/>
<file name="org-openide-actions-PrintAction.instance_hidden"/>
<file name="org-openide-actions-SaveAction.instance_hidden"/>
<file name="org-openide-actions-SaveAllAction.instance_hidden"/>
<file name="org-openide-actions-SaveAsAction.shadow_hidden"/>
</folder>
<folder name="Edit">
<file name="com-sun-hotspot-igv-coordinator-actions-SaveFilterSettingsAction.shadow">
<attr name="originalFile" stringvalue="Actions/Edit/com-sun-hotspot-igv-coordinator-actions-SaveFilterSettingsAction.instance"/>
</file>
<file name="com-sun-hotspot-igv-coordinator-actions-RemoveAction.shadow">
<attr name="originalFile" stringvalue="Actions/Edit/com-sun-hotspot-igv-coordinator-actions-RemoveAction.instance"/>
</file>
<file name="org-netbeans-core-actions-JumpNextAction.shadow_hidden"/>
<file name="org-netbeans-core-actions-JumpPrevAction.shadow_hidden"/>
<file name="org-openide-actions-CutAction.instance_hidden"/>
<file name="org-openide-actions-CopyAction.instance_hidden"/>
<file name="org-openide-actions-PasteAction.instance_hidden"/>
<file name="org-openide-actions-DeleteAction.instance_hidden"/>
<file name="org-openide-actions-FindAction.instance_hidden"/>
<file name="org-openide-actions-ReplaceAction.instance_hidden"/>
<file name="org-openide-actions-JumpNextAction.shadow_hidden"/>
<file name="org-openide-actions-JumpPrevAction.shadow_hidden"/>
</folder>
<file name="GoTo_hidden"/>
<folder name="View">
<file name="Separator1.instance_hidden"/>
<file name="Separator2.instance_hidden"/>
<file name="org-netbeans-core-actions-HTMLViewAction.instance_hidden"/>
<file name="org-netbeans-core-actions-LogAction.instance_hidden"/>
<file name="org-netbeans-core-windows-actions-ToolbarsListAction.instance_hidden"/>
</folder>
<folder name="Window">
<file name="OutlineAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/com-sun-hotspot-igv-coordinator-actions-OutlineAction.instance"/>
</file>
</folder>
</folder>
<folder name="Toolbars">
<file name="Standard.xml" url="StandardConfiguration.xml"/>
</folder>
<folder name="Windows2">
<folder name="Components">
<file name="OutlineTopComponent.settings" url="OutlineTopComponentSettings.xml"/>
</folder>
<folder name="Modes">
<file name="customLeft.wsmode" url="customLeftWsmode.xml"/>
<folder name="customLeft">
<file name="OutlineTopComponent.wstcref" url="OutlineTopComponentWstcref.xml"/>
</folder>
</folder>
</folder>
</filesystem>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="com.sun.hotspot.igv.data" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.sun.hotspot.igv.data.</description>
<import file="nbproject/build-impl.xml"/>
</project>

View File

@ -0,0 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: com.sun.hotspot.igv.data
OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/data/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="com.sun.hotspot.igv.data-impl" basedir="..">
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="netbeans.dest.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="You must define 'nbplatform.${nbplatform.active}.harness.dir'">
<condition>
<not>
<available file="${harness.dir}" type="dir"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=a403efd8
build.xml.script.CRC32=b87f73ba
build.xml.stylesheet.CRC32=79c3b980
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=a403efd8
nbproject/build-impl.xml.script.CRC32=cc649146
nbproject/build-impl.xml.stylesheet.CRC32=deb65f65

View File

@ -0,0 +1,29 @@
# Deprecated since 5.0u1; for compatibility with 5.0:
disabled.clusters=\
apisupport1,\
harness,\
ide8,\
java1,\
nb6.0,\
profiler2
disabled.modules=\
org.netbeans.core.execution,\
org.netbeans.core.multiview,\
org.netbeans.core.output2,\
org.netbeans.modules.applemenu,\
org.netbeans.modules.autoupdate.services,\
org.netbeans.modules.autoupdate.ui,\
org.netbeans.modules.core.kit,\
org.netbeans.modules.favorites,\
org.netbeans.modules.javahelp,\
org.netbeans.modules.masterfs,\
org.netbeans.modules.options.keymap,\
org.netbeans.modules.sendopts,\
org.netbeans.modules.templates,\
org.openide.compat,\
org.openide.execution,\
org.openide.util.enumerations
enabled.clusters=\
platform7
nbjdk.active=JDK_1.6
nbplatform.active=default

View File

@ -0,0 +1,2 @@
javac.source=1.5
javac.compilerargs=-Xlint -Xlint:-serial

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>com.sun.hotspot.igv.data</code-name-base>
<suite-component/>
<module-dependencies/>
<public-packages>
<package>com.sun.hotspot.igv.data</package>
<package>com.sun.hotspot.igv.data.serialization</package>
<package>com.sun.hotspot.igv.data.services</package>
</public-packages>
</data>
</configuration>
</project>

View File

@ -0,0 +1 @@
suite.dir=${basedir}/..

View File

@ -0,0 +1 @@
OpenIDE-Module-Name=Data

View File

@ -0,0 +1,44 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public class ChangedEvent<T> extends Event<ChangedListener<T>> {
private T object;
public ChangedEvent() {
}
public ChangedEvent(T object) {
this.object = object;
}
protected void fire(ChangedListener<T> l) {
l.changed(object);
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public interface ChangedEventProvider<T> {
public ChangedEvent<T> getChangedEvent();
}

View File

@ -0,0 +1,33 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public interface ChangedListener<T> {
public void changed(T source);
}

View File

@ -0,0 +1,57 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public abstract class Event<L> {
private List<L> listener;
public Event() {
listener = new ArrayList<L>();
}
public void addListener(L l) {
listener.add(l);
}
public void removeListener(L l) {
listener.remove(l);
}
public void fire() {
List<L> tmpList = new ArrayList<L>(listener);
for (L l : tmpList) {
fire(l);
}
}
protected abstract void fire(L l);
}

View File

@ -0,0 +1,91 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class GraphDocument extends Properties.Object implements ChangedEventProvider<GraphDocument> {
private List<Group> groups;
private ChangedEvent<GraphDocument> changedEvent;
public GraphDocument() {
groups = new ArrayList<Group>();
changedEvent = new ChangedEvent<GraphDocument>(this);
}
public void clear() {
groups.clear();
getChangedEvent().fire();
}
public ChangedEvent<GraphDocument> getChangedEvent() {
return changedEvent;
}
public List<Group> getGroups() {
return Collections.unmodifiableList(groups);
}
public void addGroup(Group group) {
group.setDocument(this);
groups.add(group);
getChangedEvent().fire();
}
public void removeGroup(Group group) {
if (groups.contains(group)) {
group.setDocument(null);
groups.remove(group);
getChangedEvent().fire();
}
}
public void addGraphDocument(GraphDocument document) {
for (Group g : document.groups) {
this.addGroup(g);
}
document.clear();
getChangedEvent().fire();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("GraphDocument: " + getProperties().toString() + " \n\n");
for (Group g : getGroups()) {
sb.append(g.toString());
sb.append("\n\n");
}
return sb.toString();
}
}

View File

@ -0,0 +1,141 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import com.sun.hotspot.igv.data.ChangedEvent;
import com.sun.hotspot.igv.data.ChangedEventProvider;
import com.sun.hotspot.igv.data.Properties;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class Group extends Properties.Object implements ChangedEventProvider<Group> {
private List<InputGraph> graphs;
private transient ChangedEvent<Group> changedEvent;
private GraphDocument document;
private InputMethod method;
private String assembly;
public Group() {
graphs = new ArrayList<InputGraph>();
init();
}
private void init() {
changedEvent = new ChangedEvent<Group>(this);
}
public void fireChangedEvent() {
changedEvent.fire();
}
public void setAssembly(String s) {
this.assembly = s;
}
public String getAssembly() {
return assembly;
}
public void setMethod(InputMethod method) {
this.method = method;
}
public InputMethod getMethod() {
return method;
}
void setDocument(GraphDocument document) {
this.document = document;
}
public GraphDocument getDocument() {
return document;
}
public ChangedEvent<Group> getChangedEvent() {
return changedEvent;
}
public List<InputGraph> getGraphs() {
return Collections.unmodifiableList(graphs);
}
public void addGraph(InputGraph g) {
assert g != null;
assert !graphs.contains(g);
graphs.add(g);
changedEvent.fire();
}
public void removeGraph(InputGraph g) {
int index = graphs.indexOf(g);
if (index != -1) {
graphs.remove(g);
changedEvent.fire();
}
}
public Set<Integer> getAllNodes() {
Set<Integer> result = new HashSet<Integer>();
for (InputGraph g : graphs) {
Set<Integer> ids = g.getNodesAsSet();
result.addAll(g.getNodesAsSet());
for (Integer i : ids) {
result.add(-i);
}
}
return result;
}
public InputGraph getLastAdded() {
if (graphs.size() == 0) {
return null;
}
return graphs.get(graphs.size() - 1);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Group " + getProperties().toString() + "\n");
for (InputGraph g : graphs) {
sb.append(g.toString());
sb.append("\n");
}
return sb.toString();
}
public String getName() {
return getProperties().get("name");
}
}

View File

@ -0,0 +1,140 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class InputBlock {
private List<InputNode> nodes;
private List<String> successorNames;
private String name;
private InputGraph graph;
private Rectangle bounds;
private Set<InputBlock> successors;
private Set<InputBlock> predecessors;
private Set<InputBlockEdge> inputs;
private Set<InputBlockEdge> outputs;
public InputBlock(InputGraph graph, String name) {
this.graph = graph;
this.name = name;
nodes = new ArrayList<InputNode>();
successorNames = new ArrayList<String>();
successors = new HashSet<InputBlock>();
predecessors = new HashSet<InputBlock>();
inputs = new HashSet<InputBlockEdge>();
outputs = new HashSet<InputBlockEdge>();
}
public void removeSuccessor(InputBlock b) {
if (successors.contains(b)) {
successors.remove(b);
b.predecessors.remove(this);
InputBlockEdge e = new InputBlockEdge(this, b);
assert outputs.contains(e);
outputs.remove(e);
assert b.inputs.contains(e);
b.inputs.remove(e);
}
}
public String getName() {
return name;
}
public void setName(String s) {
name = s;
}
public List<InputNode> getNodes() {
return Collections.unmodifiableList(nodes);
}
public void addNode(int id) {
InputNode n = graph.getNode(id);
assert n != null;
graph.setBlock(n, this);
addNode(graph.getNode(id));
}
public void addNode(InputNode node) {
assert !nodes.contains(node);
nodes.add(node);
}
public Set<InputBlock> getPredecessors() {
return Collections.unmodifiableSet(predecessors);
}
public Set<InputBlock> getSuccessors() {
return Collections.unmodifiableSet(successors);
}
public Set<InputBlockEdge> getInputs() {
return Collections.unmodifiableSet(inputs);
}
public Set<InputBlockEdge> getOutputs() {
return Collections.unmodifiableSet(outputs);
}
// resolveBlockLinks must be called afterwards
public void addSuccessor(String name) {
successorNames.add(name);
}
public void resolveBlockLinks() {
for (String s : successorNames) {
InputBlock b = graph.getBlock(s);
addSuccessor(b);
}
successorNames.clear();
}
public void addSuccessor(InputBlock b) {
if (!successors.contains(b)) {
successors.add(b);
b.predecessors.add(this);
InputBlockEdge e = new InputBlockEdge(this, b);
outputs.add(e);
b.inputs.add(e);
}
}
@Override
public String toString() {
return this.getName();
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public class InputBlockEdge {
private InputBlock from;
private InputBlock to;
public InputBlockEdge(InputBlock from, InputBlock to) {
assert from != null;
assert to != null;
this.from = from;
this.to = to;
}
public InputBlock getFrom() {
return from;
}
public InputBlock getTo() {
return to;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof InputBlockEdge && obj != null) {
InputBlockEdge e = (InputBlockEdge) obj;
return e.from.equals(from) && e.to.equals(to);
}
return super.equals(obj);
}
@Override
public int hashCode() {
int hash = from.hashCode();
hash = 59 * hash + to.hashCode();
return hash;
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public class InputBytecode {
private int bci;
private String name;
private InputMethod inlined;
public InputBytecode(int bci, String name) {
this.bci = bci;
this.name = name;
}
public InputMethod getInlined() {
return inlined;
}
public void setInlined(InputMethod inlined) {
this.inlined = inlined;
}
public int getBci() {
return bci;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,92 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public class InputEdge {
public enum State {
SAME,
NEW,
DELETED
}
private char toIndex;
private int from;
private int to;
private State state;
public InputEdge(char toIndex, int from, int to) {
this.toIndex = toIndex;
this.from = from;
this.to = to;
this.state = State.SAME;
}
public State getState() {
return state;
}
public void setState(State x) {
this.state = x;
}
public char getToIndex() {
return toIndex;
}
public String getName() {
return "in" + toIndex;
}
public int getFrom() {
return from;
}
public int getTo() {
return to;
}
@Override
public boolean equals(Object o) {
if (o == null || !(o instanceof InputEdge)) {
return false;
}
InputEdge conn2 = (InputEdge) o;
return conn2.toIndex == toIndex && conn2.from == from && conn2.to == to;
}
@Override
public String toString() {
return "Edge from " + from + " to " + to + "(" + (int) toIndex + ") ";
}
@Override
public int hashCode() {
return (from << 20 | to << 8 | toIndex);
}
}

View File

@ -0,0 +1,249 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import com.sun.hotspot.igv.data.Properties;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class InputGraph extends Properties.Object {
private Map<Integer, InputNode> nodes;
private Set<InputEdge> edges;
private Group parent;
private Map<String, InputBlock> blocks;
private Map<Integer, InputBlock> nodeToBlock;
private boolean isDifferenceGraph;
public InputGraph(Group parent) {
this(parent, null);
}
public InputGraph(Group parent, InputGraph last) {
this(parent, last, "");
}
private void clearBlocks() {
blocks.clear();
nodeToBlock.clear();
}
public InputGraph(Group parent, InputGraph last, String name) {
this.parent = parent;
setName(name);
nodes = new Hashtable<Integer, InputNode>();
edges = new HashSet<InputEdge>();
blocks = new Hashtable<String, InputBlock>();
nodeToBlock = new Hashtable<Integer, InputBlock>();
if (last != null) {
for (InputNode n : last.getNodes()) {
addNode(n);
}
for (InputEdge c : last.getEdges()) {
addEdge(c);
}
}
}
public void schedule(Collection<InputBlock> newBlocks) {
clearBlocks();
InputBlock noBlock = new InputBlock(this, "no block");
Set<InputNode> scheduledNodes = new HashSet<InputNode>();
for (InputBlock b : newBlocks) {
for (InputNode n : b.getNodes()) {
assert !scheduledNodes.contains(n);
scheduledNodes.add(n);
}
}
for (InputNode n : this.getNodes()) {
assert nodes.get(n.getId()) == n;
if (!scheduledNodes.contains(n)) {
noBlock.addNode(n.getId());
}
}
if (noBlock.getNodes().size() != 0) {
newBlocks.add(noBlock);
}
for (InputBlock b : newBlocks) {
addBlock(b);
}
for (InputNode n : this.getNodes()) {
assert this.getBlock(n) != null;
}
}
public void setBlock(InputNode node, InputBlock block) {
nodeToBlock.put(node.getId(), block);
}
public InputBlock getBlock(int nodeId) {
return nodeToBlock.get(nodeId);
}
public InputBlock getBlock(InputNode node) {
return getBlock(node.getId());
}
public InputGraph getNext() {
List<InputGraph> list = parent.getGraphs();
if (!list.contains(this)) {
return null;
}
int index = list.indexOf(this);
if (index == list.size() - 1) {
return null;
} else {
return list.get(index + 1);
}
}
public InputGraph getPrev() {
List<InputGraph> list = parent.getGraphs();
if (!list.contains(this)) {
return null;
}
int index = list.indexOf(this);
if (index == 0) {
return null;
} else {
return list.get(index - 1);
}
}
public String getName() {
return getProperties().get("name");
}
public String getAbsoluteName() {
String result = getName();
if (this.parent != null) {
result = parent.getName() + ": " + result;
}
return result;
}
public Collection<InputNode> getNodes() {
return Collections.unmodifiableCollection(nodes.values());
}
public Set<Integer> getNodesAsSet() {
return Collections.unmodifiableSet(nodes.keySet());
}
public Collection<InputBlock> getBlocks() {
return Collections.unmodifiableCollection(blocks.values());
}
public void addNode(InputNode node) {
nodes.put(node.getId(), node);
}
public InputNode getNode(int id) {
return nodes.get(id);
}
public InputNode removeNode(int index) {
return nodes.remove(index);
}
public Set<InputEdge> getEdges() {
return Collections.unmodifiableSet(edges);
}
public void removeEdge(InputEdge c) {
assert edges.contains(c);
edges.remove(c);
assert !edges.contains(c);
}
public void addEdge(InputEdge c) {
assert !edges.contains(c);
edges.add(c);
assert edges.contains(c);
}
public Group getGroup() {
return parent;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Graph " + getName() + " " + getProperties().toString() + "\n");
for (InputNode n : nodes.values()) {
sb.append(n.toString());
sb.append("\n");
}
for (InputEdge c : edges) {
sb.append(c.toString());
sb.append("\n");
}
return sb.toString();
}
public void addBlock(InputBlock b) {
blocks.put(b.getName(), b);
for (InputNode n : b.getNodes()) {
this.nodeToBlock.put(n.getId(), b);
}
}
public void resolveBlockLinks() {
for (InputBlock b : blocks.values()) {
b.resolveBlockLinks();
}
}
public void setName(String s) {
getProperties().setProperty("name", s);
}
public InputBlock getBlock(String s) {
return blocks.get(s);
}
public boolean isDifferenceGraph() {
return this.isDifferenceGraph;
}
public void setIsDifferenceGraph(boolean b) {
isDifferenceGraph = b;
}
}

View File

@ -0,0 +1,127 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import com.sun.hotspot.igv.data.Properties;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class InputMethod extends Properties.Object {
private String name;
private int bci;
private String shortName;
private List<InputMethod> inlined;
private InputMethod parentMethod;
private Group group;
private List<InputBytecode> bytecodes;
/** Creates a new instance of InputMethod */
public InputMethod(Group parent, String name, String shortName, int bci) {
this.group = parent;
this.name = name;
this.bci = bci;
this.shortName = shortName;
inlined = new ArrayList<InputMethod>();
bytecodes = new ArrayList<InputBytecode>();
}
public List<InputBytecode> getBytecodes() {
return Collections.unmodifiableList(bytecodes);
}
public List<InputMethod> getInlined() {
return Collections.unmodifiableList(inlined);
}
public void addInlined(InputMethod m) {
// assert bci unique
for (InputMethod m2 : inlined) {
assert m2.getBci() != m.getBci();
}
inlined.add(m);
assert m.parentMethod == null;
m.parentMethod = this;
for (InputBytecode bc : bytecodes) {
if (bc.getBci() == m.getBci()) {
bc.setInlined(m);
}
}
}
public Group getGroup() {
return group;
}
public String getShortName() {
return shortName;
}
public void setBytecodes(String text) {
String[] strings = text.split("\n");
int oldNumber = -1;
for (String s : strings) {
if (s.length() > 0 && Character.isDigit(s.charAt(0))) {
s = s.trim();
int spaceIndex = s.indexOf(' ');
String numberString = s.substring(0, spaceIndex);
String tmpName = s.substring(spaceIndex + 1, s.length());
int number = -1;
number = Integer.parseInt(numberString);
// assert correct order of bytecodes
assert number > oldNumber;
InputBytecode bc = new InputBytecode(number, tmpName);
bytecodes.add(bc);
for (InputMethod m : inlined) {
if (m.getBci() == number) {
bc.setInlined(m);
break;
}
}
}
}
}
public String getName() {
return name;
}
public int getBci() {
return bci;
}
}

View File

@ -0,0 +1,73 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public class InputNode extends Properties.Object {
private int id;
public InputNode(InputNode n) {
super(n);
setId(n.id);
}
public InputNode(int id) {
setId(id);
}
public void setId(int id) {
this.id = id;
getProperties().setProperty("id", "" + id);
}
public int getId() {
return id;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof InputNode)) {
return false;
}
InputNode n = (InputNode) o;
if (n.id != id) {
return false;
}
return getProperties().equals(n.getProperties());
}
@Override
public int hashCode() {
return id;
}
@Override
public String toString() {
return "Node " + id + " " + getProperties().toString();
}
}

View File

@ -0,0 +1,72 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
/**
*
* @author Thomas Wuerthinger
*/
public class Pair<L, R> {
private L l;
private R r;
public Pair() {
}
public Pair(L l, R r) {
this.l = l;
this.r = r;
}
public L getLeft() {
return l;
}
public void setLeft(L l) {
this.l = l;
}
public R getRight() {
return r;
}
public void setRight(R r) {
this.r = r;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) {
return false;
}
Pair obj = (Pair) o;
return l.equals(obj.l) && r.equals(obj.r);
}
@Override
public int hashCode() {
return l.hashCode() * 71 + r.hashCode();
}
}

View File

@ -0,0 +1,288 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author Thomas Wuerthinger
*/
public class Properties implements Serializable {
public static final long serialVersionUID = 1L;
private Map<String, Property> map;
public Properties() {
map = new HashMap<String, Property>(5);
}
@Override
public boolean equals(java.lang.Object o) {
if (!(o instanceof Properties)) {
return false;
}
Properties p = (Properties) o;
if (getProperties().size() != p.getProperties().size()) {
return false;
}
for (Property prop : getProperties()) {
String value = p.get(prop.getName());
if (value == null || !value.equals(prop.getValue())) {
return false;
}
}
return true;
}
@Override
public int hashCode() {
int hash = 5;
hash = 83 * hash + (this.map != null ? this.map.hashCode() : 0);
return hash;
}
public Properties(String name, String value) {
this();
this.add(new Property(name, value));
}
public Properties(String name, String value, String name1, String value1) {
this(name, value);
this.add(new Property(name1, value1));
}
public Properties(String name, String value, String name1, String value1, String name2, String value2) {
this(name, value, name1, value1);
this.add(new Property(name2, value2));
}
public Properties(Properties p) {
map = new HashMap<String, Property>(p.map);
}
public static class Object implements Provider {
private Properties properties;
public Object() {
properties = new Properties();
}
public Object(Properties.Object object) {
properties = new Properties(object.getProperties());
}
public Properties getProperties() {
return properties;
}
}
public interface PropertyMatcher {
String getName();
boolean match(String value);
}
public static class InvertPropertyMatcher implements PropertyMatcher {
private PropertyMatcher matcher;
public InvertPropertyMatcher(PropertyMatcher matcher) {
this.matcher = matcher;
}
public String getName() {
return matcher.getName();
}
public boolean match(String p) {
return !matcher.match(p);
}
}
public static class StringPropertyMatcher implements PropertyMatcher {
private String name;
private String value;
public StringPropertyMatcher(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public boolean match(String p) {
return p.equals(value);
}
}
public static class RegexpPropertyMatcher implements PropertyMatcher {
private String name;
private Pattern valuePattern;
public RegexpPropertyMatcher(String name, String value) {
this.name = name;
valuePattern = Pattern.compile(value);
}
public String getName() {
return name;
}
public boolean match(String p) {
Matcher m = valuePattern.matcher(p);
return m.matches();
}
}
public Property selectSingle(PropertyMatcher matcher) {
Property p = this.map.get(matcher.getName());
if (p == null) {
return null;
}
if (matcher.match(p.getValue())) {
return p;
} else {
return null;
}
}
public interface Provider {
public Properties getProperties();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (Property p : map.values()) {
sb.append(p.toString());
}
return sb.append("]").toString();
}
public static class PropertySelector<T extends Properties.Provider> {
private Collection<T> objects;
public PropertySelector(Collection<T> objects) {
this.objects = objects;
}
public T selectSingle(final String name, final String value) {
return selectSingle(new StringPropertyMatcher(name, value));
}
public T selectSingle(PropertyMatcher matcher) {
for (T t : objects) {
Property p = t.getProperties().selectSingle(matcher);
if (p != null) {
return t;
}
}
return null;
}
public List<T> selectMultiple(final String name, final String value) {
return selectMultiple(new StringPropertyMatcher(name, value));
}
public List<T> selectMultiple(PropertyMatcher matcher) {
List<T> result = new ArrayList<T>();
for (T t : objects) {
Property p = t.getProperties().selectSingle(matcher);
if (p != null) {
result.add(t);
}
}
return result;
}
}
public String get(String key) {
Property p = map.get(key);
if (p == null) {
return null;
} else {
return p.getValue();
}
}
public String getProperty(String string) {
return get(string);
}
public Property setProperty(String name, String value) {
if (value == null) {
// remove this property
return map.remove(name);
} else {
Property p = map.get(name);
if (p == null) {
p = new Property(name, value);
map.put(name, p);
} else {
p.setValue(value);
}
return p;
}
}
public Collection<Property> getProperties() {
return Collections.unmodifiableCollection(map.values());
}
public void add(Properties properties) {
for (Property p : properties.getProperties()) {
add(p);
}
}
public void add(Property property) {
assert property.getName() != null;
assert property.getValue() != null;
map.put(property.getName(), property);
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data;
import java.io.Serializable;
/**
*
* @author Thomas Wuerthinger
*/
public class Property implements Serializable {
public static final long serialVersionUID = 1L;
private String name;
private String value;
public Property() {
this(null, null);
}
public Property(Property p) {
this(p.getName(), p.getValue());
}
public Property(String name) {
this(name, null);
}
public Property(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String s) {
this.name = s;
}
public void setValue(String s) {
this.value = s;
}
@Override
public String toString() {
return name + " = " + value + "; ";
}
}

View File

@ -0,0 +1,422 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data.serialization;
import com.sun.hotspot.igv.data.GraphDocument;
import com.sun.hotspot.igv.data.Group;
import com.sun.hotspot.igv.data.InputBlock;
import com.sun.hotspot.igv.data.InputEdge;
import com.sun.hotspot.igv.data.InputGraph;
import com.sun.hotspot.igv.data.InputMethod;
import com.sun.hotspot.igv.data.InputNode;
import com.sun.hotspot.igv.data.Properties;
import com.sun.hotspot.igv.data.Property;
import com.sun.hotspot.igv.data.services.GroupCallback;
import com.sun.hotspot.igv.data.serialization.XMLParser.ElementHandler;
import com.sun.hotspot.igv.data.serialization.XMLParser.HandoverElementHandler;
import com.sun.hotspot.igv.data.serialization.XMLParser.ParseMonitor;
import com.sun.hotspot.igv.data.serialization.XMLParser.TopElementHandler;
import java.io.IOException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
*
* @author Thomas Wuerthinger
*/
public class Parser {
public static final String INDENT = " ";
public static final String TOP_ELEMENT = "graphDocument";
public static final String GROUP_ELEMENT = "group";
public static final String GRAPH_ELEMENT = "graph";
public static final String ROOT_ELEMENT = "graphDocument";
public static final String PROPERTIES_ELEMENT = "properties";
public static final String EDGES_ELEMENT = "edges";
public static final String PROPERTY_ELEMENT = "p";
public static final String EDGE_ELEMENT = "edge";
public static final String NODE_ELEMENT = "node";
public static final String NODES_ELEMENT = "nodes";
public static final String REMOVE_EDGE_ELEMENT = "removeEdge";
public static final String REMOVE_NODE_ELEMENT = "removeNode";
public static final String METHOD_NAME_PROPERTY = "name";
public static final String METHOD_IS_PUBLIC_PROPERTY = "public";
public static final String METHOD_IS_STATIC_PROPERTY = "static";
public static final String TRUE_VALUE = "true";
public static final String NODE_NAME_PROPERTY = "name";
public static final String EDGE_NAME_PROPERTY = "name";
public static final String NODE_ID_PROPERTY = "id";
public static final String FROM_PROPERTY = "from";
public static final String TO_PROPERTY = "to";
public static final String PROPERTY_NAME_PROPERTY = "name";
public static final String GRAPH_NAME_PROPERTY = "name";
public static final String TO_INDEX_PROPERTY = "index";
public static final String METHOD_ELEMENT = "method";
public static final String INLINE_ELEMENT = "inline";
public static final String BYTECODES_ELEMENT = "bytecodes";
public static final String METHOD_BCI_PROPERTY = "bci";
public static final String METHOD_SHORT_NAME_PROPERTY = "shortName";
public static final String CONTROL_FLOW_ELEMENT = "controlFlow";
public static final String BLOCK_NAME_PROPERTY = "name";
public static final String BLOCK_ELEMENT = "block";
public static final String SUCCESSORS_ELEMENT = "successors";
public static final String SUCCESSOR_ELEMENT = "successor";
public static final String ASSEMBLY_ELEMENT = "assembly";
public static final String DIFFERENCE_PROPERTY = "difference";
private TopElementHandler xmlDocument = new TopElementHandler();
private boolean difference;
private GroupCallback groupCallback;
// <graphDocument>
private ElementHandler<GraphDocument, Object> topHandler = new ElementHandler<GraphDocument, Object>(TOP_ELEMENT) {
@Override
protected GraphDocument start() throws SAXException {
return new GraphDocument();
}
};
// <group>
private ElementHandler<Group, GraphDocument> groupHandler = new XMLParser.ElementHandler<Group, GraphDocument>(GROUP_ELEMENT) {
@Override
protected Group start() throws SAXException {
Group group = new Group();
Parser.this.difference = false;
String differenceProperty = this.readAttribute(DIFFERENCE_PROPERTY);
if (differenceProperty != null && (differenceProperty.equals("1") || differenceProperty.equals("true"))) {
Parser.this.difference = true;
}
ParseMonitor monitor = getMonitor();
if (monitor != null) {
monitor.setState(group.getName());
}
return group;
}
@Override
protected void end(String text) throws SAXException {
if (groupCallback == null) {
getParentObject().addGroup(getObject());
}
}
};
private HandoverElementHandler<Group> assemblyHandler = new XMLParser.HandoverElementHandler<Group>(ASSEMBLY_ELEMENT, true) {
@Override
protected void end(String text) throws SAXException {
getParentObject().setAssembly(text);
}
};
// <method>
private ElementHandler<InputMethod, Group> methodHandler = new XMLParser.ElementHandler<InputMethod, Group>(METHOD_ELEMENT) {
@Override
protected InputMethod start() throws SAXException {
InputMethod method = parseMethod(this, getParentObject());
getParentObject().setMethod(method);
return method;
}
};
private InputMethod parseMethod(XMLParser.ElementHandler handler, Group group) throws SAXException {
String s = handler.readRequiredAttribute(METHOD_BCI_PROPERTY);
int bci = 0;
try {
bci = Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new SAXException(e);
}
InputMethod method = new InputMethod(group, handler.readRequiredAttribute(METHOD_NAME_PROPERTY), handler.readRequiredAttribute(METHOD_SHORT_NAME_PROPERTY), bci);
return method;
}
// <bytecodes>
private HandoverElementHandler<InputMethod> bytecodesHandler = new XMLParser.HandoverElementHandler<InputMethod>(BYTECODES_ELEMENT, true) {
@Override
protected void end(String text) throws SAXException {
getParentObject().setBytecodes(text);
}
};
// <inlined>
private HandoverElementHandler<InputMethod> inlinedHandler = new XMLParser.HandoverElementHandler<InputMethod>(INLINE_ELEMENT);
// <inlined><method>
private ElementHandler<InputMethod, InputMethod> inlinedMethodHandler = new XMLParser.ElementHandler<InputMethod, InputMethod>(METHOD_ELEMENT) {
@Override
protected InputMethod start() throws SAXException {
InputMethod method = parseMethod(this, getParentObject().getGroup());
getParentObject().addInlined(method);
return method;
}
};
// <graph>
private ElementHandler<InputGraph, Group> graphHandler = new XMLParser.ElementHandler<InputGraph, Group>(GRAPH_ELEMENT) {
private InputGraph graph;
@Override
protected InputGraph start() throws SAXException {
String name = readAttribute(GRAPH_NAME_PROPERTY);
InputGraph previous = getParentObject().getLastAdded();
if (!difference) {
previous = null;
}
InputGraph curGraph = new InputGraph(getParentObject(), previous, name);
getParentObject().addGraph(curGraph);
this.graph = curGraph;
return curGraph;
}
@Override
protected void end(String text) throws SAXException {
graph.resolveBlockLinks();
}
};
// <nodes>
private HandoverElementHandler<InputGraph> nodesHandler = new HandoverElementHandler<InputGraph>(NODES_ELEMENT);
// <controlFlow>
private HandoverElementHandler<InputGraph> controlFlowHandler = new HandoverElementHandler<InputGraph>(CONTROL_FLOW_ELEMENT);
// <block>
private ElementHandler<InputBlock, InputGraph> blockHandler = new ElementHandler<InputBlock, InputGraph>(BLOCK_ELEMENT) {
@Override
protected InputBlock start() throws SAXException {
InputGraph graph = getParentObject();
String name = readRequiredAttribute(BLOCK_NAME_PROPERTY);
InputBlock b = new InputBlock(getParentObject(), name);
graph.addBlock(b);
return b;
}
};
// <nodes>
private HandoverElementHandler<InputBlock> blockNodesHandler = new HandoverElementHandler<InputBlock>(NODES_ELEMENT);
// <node>
private ElementHandler<InputBlock, InputBlock> blockNodeHandler = new ElementHandler<InputBlock, InputBlock>(NODE_ELEMENT) {
@Override
protected InputBlock start() throws SAXException {
String s = readRequiredAttribute(NODE_ID_PROPERTY);
int id = 0;
try {
id = Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new SAXException(e);
}
getParentObject().addNode(id);
return getParentObject();
}
};
// <successors>
private HandoverElementHandler<InputBlock> successorsHandler = new HandoverElementHandler<InputBlock>(SUCCESSORS_ELEMENT);
// <successor>
private ElementHandler<InputBlock, InputBlock> successorHandler = new ElementHandler<InputBlock, InputBlock>(SUCCESSOR_ELEMENT) {
@Override
protected InputBlock start() throws SAXException {
String name = readRequiredAttribute(BLOCK_NAME_PROPERTY);
getParentObject().addSuccessor(name);
return getParentObject();
}
};
// <node>
private ElementHandler<InputNode, InputGraph> nodeHandler = new ElementHandler<InputNode, InputGraph>(NODE_ELEMENT) {
@Override
protected InputNode start() throws SAXException {
String s = readRequiredAttribute(NODE_ID_PROPERTY);
int id = 0;
try {
id = Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new SAXException(e);
}
InputNode node = new InputNode(id);
getParentObject().addNode(node);
return node;
}
};
// <removeNode>
private ElementHandler<InputNode, InputGraph> removeNodeHandler = new ElementHandler<InputNode, InputGraph>(REMOVE_NODE_ELEMENT) {
@Override
protected InputNode start() throws SAXException {
String s = readRequiredAttribute(NODE_ID_PROPERTY);
int id = 0;
try {
id = Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new SAXException(e);
}
return getParentObject().removeNode(id);
}
};
// <graph>
private HandoverElementHandler<InputGraph> edgesHandler = new HandoverElementHandler<InputGraph>(EDGES_ELEMENT);
// Local class for edge elements
private static class EdgeElementHandler extends ElementHandler<InputEdge, InputGraph> {
public EdgeElementHandler(String name) {
super(name);
}
@Override
protected InputEdge start() throws SAXException {
int toIndex = 0;
int from = -1;
int to = -1;
try {
String toIndexString = readAttribute(TO_INDEX_PROPERTY);
if (toIndexString != null) {
toIndex = Integer.parseInt(toIndexString);
}
from = Integer.parseInt(readRequiredAttribute(FROM_PROPERTY));
to = Integer.parseInt(readRequiredAttribute(TO_PROPERTY));
} catch (NumberFormatException e) {
throw new SAXException(e);
}
InputEdge conn = new InputEdge((char) toIndex, from, to);
return start(conn);
}
protected InputEdge start(InputEdge conn) throws SAXException {
return conn;
}
}
// <edge>
private EdgeElementHandler edgeHandler = new EdgeElementHandler(EDGE_ELEMENT) {
@Override
protected InputEdge start(InputEdge conn) throws SAXException {
getParentObject().addEdge(conn);
return conn;
}
};
// <removeEdge>
private EdgeElementHandler removeEdgeHandler = new EdgeElementHandler(REMOVE_EDGE_ELEMENT) {
@Override
protected InputEdge start(InputEdge conn) throws SAXException {
getParentObject().removeEdge(conn);
return conn;
}
};
// <properties>
private HandoverElementHandler<Properties.Provider> propertiesHandler = new HandoverElementHandler<Properties.Provider>(PROPERTIES_ELEMENT);
// <properties>
private HandoverElementHandler<Group> groupPropertiesHandler = new HandoverElementHandler<Group>(PROPERTIES_ELEMENT) {
@Override
public void end(String text) throws SAXException {
if (groupCallback != null) {
groupCallback.started(getParentObject());
}
}
};
// <property>
private ElementHandler<Property, Properties.Provider> propertyHandler = new XMLParser.ElementHandler<Property, Properties.Provider>(PROPERTY_ELEMENT, true) {
@Override
public Property start() throws SAXException {
String value = "";
String name = readRequiredAttribute(PROPERTY_NAME_PROPERTY).intern();
return getParentObject().getProperties().setProperty(name, value);
}
@Override
public void end(String text) {
getObject().setValue(text.trim().intern());
}
};
public Parser() {
this(null);
}
public Parser(GroupCallback groupCallback) {
this.groupCallback = groupCallback;
// Initialize dependencies
xmlDocument.addChild(topHandler);
topHandler.addChild(groupHandler);
groupHandler.addChild(methodHandler);
groupHandler.addChild(assemblyHandler);
groupHandler.addChild(graphHandler);
methodHandler.addChild(inlinedHandler);
methodHandler.addChild(bytecodesHandler);
inlinedHandler.addChild(inlinedMethodHandler);
inlinedMethodHandler.addChild(bytecodesHandler);
inlinedMethodHandler.addChild(inlinedHandler);
graphHandler.addChild(nodesHandler);
graphHandler.addChild(edgesHandler);
graphHandler.addChild(controlFlowHandler);
controlFlowHandler.addChild(blockHandler);
blockHandler.addChild(successorsHandler);
successorsHandler.addChild(successorHandler);
blockHandler.addChild(blockNodesHandler);
blockNodesHandler.addChild(blockNodeHandler);
nodesHandler.addChild(nodeHandler);
nodesHandler.addChild(removeNodeHandler);
edgesHandler.addChild(edgeHandler);
edgesHandler.addChild(removeEdgeHandler);
methodHandler.addChild(propertiesHandler);
inlinedMethodHandler.addChild(propertiesHandler);
topHandler.addChild(propertiesHandler);
groupHandler.addChild(groupPropertiesHandler);
graphHandler.addChild(propertiesHandler);
nodeHandler.addChild(propertiesHandler);
propertiesHandler.addChild(propertyHandler);
groupPropertiesHandler.addChild(propertyHandler);
}
// Returns a new GraphDocument object deserialized from an XML input source.
public GraphDocument parse(XMLReader reader, InputSource source, XMLParser.ParseMonitor monitor) throws SAXException {
reader.setContentHandler(new XMLParser(xmlDocument, monitor));
try {
reader.parse(source);
} catch (IOException ex) {
throw new SAXException(ex);
}
return topHandler.getObject();
}
}

View File

@ -0,0 +1,217 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data.serialization;
import com.sun.hotspot.igv.data.GraphDocument;
import com.sun.hotspot.igv.data.Group;
import com.sun.hotspot.igv.data.InputBlock;
import com.sun.hotspot.igv.data.InputBytecode;
import com.sun.hotspot.igv.data.InputEdge;
import com.sun.hotspot.igv.data.InputGraph;
import com.sun.hotspot.igv.data.InputMethod;
import com.sun.hotspot.igv.data.InputNode;
import com.sun.hotspot.igv.data.Properties;
import com.sun.hotspot.igv.data.Property;
import java.io.IOException;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class Printer {
public void export(Writer writer, GraphDocument document) {
XMLWriter xmlWriter = new XMLWriter(writer);
try {
export(xmlWriter, document);
} catch (IOException ex) {
}
}
private void export(XMLWriter xmlWriter, GraphDocument document) throws IOException {
xmlWriter.startTag(Parser.ROOT_ELEMENT);
xmlWriter.writeProperties(document.getProperties());
for (Group g : document.getGroups()) {
export(xmlWriter, g);
}
xmlWriter.endTag();
xmlWriter.flush();
}
private void export(XMLWriter writer, Group g) throws IOException {
Properties attributes = new Properties();
attributes.add(new Property("difference", Boolean.toString(true)));
writer.startTag(Parser.GROUP_ELEMENT, attributes);
writer.writeProperties(g.getProperties());
if (g.getMethod() != null) {
export(writer, g.getMethod());
}
InputGraph previous = null;
for (InputGraph graph : g.getGraphs()) {
export(writer, graph, previous, true);
previous = graph;
}
writer.endTag();
}
public void export(XMLWriter writer, InputGraph graph, InputGraph previous, boolean difference) throws IOException {
writer.startTag(Parser.GRAPH_ELEMENT);
writer.writeProperties(graph.getProperties());
writer.startTag(Parser.NODES_ELEMENT);
Set<InputNode> removed = new HashSet<InputNode>();
Set<InputNode> equal = new HashSet<InputNode>();
if (previous != null) {
for (InputNode n : previous.getNodes()) {
int id = n.getId();
InputNode n2 = graph.getNode(id);
if (n2 == null) {
removed.add(n);
} else if (n.equals(n2)) {
equal.add(n);
}
}
}
if (difference) {
for (InputNode n : removed) {
writer.simpleTag(Parser.REMOVE_NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, Integer.toString(n.getId())));
}
}
for (InputNode n : graph.getNodes()) {
if (!difference || !equal.contains(n)) {
writer.startTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, Integer.toString(n.getId())));
writer.writeProperties(n.getProperties());
writer.endTag();
}
}
writer.endTag();
writer.startTag(Parser.EDGES_ELEMENT);
Set<InputEdge> removedEdges = new HashSet<InputEdge>();
Set<InputEdge> equalEdges = new HashSet<InputEdge>();
if (previous != null) {
for (InputEdge e : previous.getEdges()) {
if (graph.getEdges().contains(e)) {
equalEdges.add(e);
} else {
removedEdges.add(e);
}
}
}
if (difference) {
for (InputEdge e : removedEdges) {
writer.simpleTag(Parser.REMOVE_EDGE_ELEMENT, createProperties(e));
}
}
for (InputEdge e : graph.getEdges()) {
if (!difference || !equalEdges.contains(e)) {
if (!equalEdges.contains(e)) {
writer.simpleTag(Parser.EDGE_ELEMENT, createProperties(e));
}
}
}
writer.endTag();
writer.startTag(Parser.CONTROL_FLOW_ELEMENT);
for (InputBlock b : graph.getBlocks()) {
writer.startTag(Parser.BLOCK_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, b.getName()));
writer.startTag(Parser.SUCCESSORS_ELEMENT);
for (InputBlock s : b.getSuccessors()) {
writer.simpleTag(Parser.SUCCESSOR_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, s.getName()));
}
writer.endTag();
writer.startTag(Parser.NODES_ELEMENT);
for (InputNode n : b.getNodes()) {
writer.simpleTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, n.getId() + ""));
}
writer.endTag();
writer.endTag();
}
writer.endTag();
writer.endTag();
}
private void export(XMLWriter w, InputMethod method) throws IOException {
w.startTag(Parser.METHOD_ELEMENT, new Properties(Parser.METHOD_BCI_PROPERTY, method.getBci() + "", Parser.METHOD_NAME_PROPERTY, method.getName(), Parser.METHOD_SHORT_NAME_PROPERTY, method.getShortName()));
w.writeProperties(method.getProperties());
if (method.getInlined().size() > 0) {
w.startTag(Parser.INLINE_ELEMENT);
for (InputMethod m : method.getInlined()) {
export(w, m);
}
w.endTag();
}
w.startTag(Parser.BYTECODES_ELEMENT);
StringBuilder b = new StringBuilder();
b.append("<![CDATA[\n");
for (InputBytecode code : method.getBytecodes()) {
b.append(code.getBci());
b.append(" ");
b.append(code.getName());
b.append("\n");
}
b.append("]]>");
w.write(b.toString());
w.endTag();
w.endTag();
}
private Properties createProperties(InputEdge edge) {
Properties p = new Properties();
p.setProperty(Parser.TO_INDEX_PROPERTY, Integer.toString(edge.getToIndex()));
p.setProperty(Parser.TO_PROPERTY, Integer.toString(edge.getTo()));
p.setProperty(Parser.FROM_PROPERTY, Integer.toString(edge.getFrom()));
return p;
}
}

View File

@ -0,0 +1,254 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data.serialization;
import com.sun.hotspot.igv.data.Property;
import com.sun.hotspot.igv.data.Properties;
import java.util.Hashtable;
import java.util.Stack;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
*
* @author Thomas Wuerthinger
*/
public class XMLParser implements ContentHandler {
public static interface ParseMonitor {
public void setProgress(double d);
public void setState(String state);
}
public static class MissingAttributeException extends SAXException {
private String name;
public MissingAttributeException(String name) {
super("Missing attribute \"" + name + "\"");
this.name = name;
}
public String getAttributeName() {
return this.getMessage();
}
}
public static class HandoverElementHandler<P> extends ElementHandler<P, P> {
@Override
protected P start() throws SAXException {
return getParentObject();
}
public HandoverElementHandler(String name) {
super(name);
}
public HandoverElementHandler(String name, boolean needsText) {
super(name, needsText);
}
}
public static class TopElementHandler<P> extends ElementHandler<P, Object> {
public TopElementHandler() {
super(null);
}
}
public static class ElementHandler<T, P> {
private String name;
private T object;
private Attributes attr;
private StringBuilder currentText;
private ParseMonitor monitor;
private Hashtable<String, ElementHandler<?, ? super T>> hashtable;
private boolean needsText;
private ElementHandler<P, ?> parentElement;
public ElementHandler(String name) {
this(name, false);
}
public ElementHandler<P, ?> getParentElement() {
return parentElement;
}
public P getParentObject() {
return getParentElement().getObject();
}
protected boolean needsText() {
return needsText;
}
public ElementHandler(String name, boolean needsText) {
this.hashtable = new Hashtable<String, ElementHandler<?, ? super T>>();
this.name = name;
this.needsText = needsText;
}
public ParseMonitor getMonitor() {
return monitor;
}
public ElementHandler<?, ? super T> getChild(String name) {
return hashtable.get(name);
}
public void addChild(ElementHandler<?, ? super T> handler) {
assert handler != null;
hashtable.put(handler.getName(), handler);
}
public String getName() {
return name;
}
public T getObject() {
return object;
}
public String readAttribute(String name) {
return attr.getValue(name);
}
public String readRequiredAttribute(String name) throws SAXException {
String s = readAttribute(name);
if (s == null) {
throw new MissingAttributeException(name);
}
return s;
}
public void processAttributesAsProperties(Properties p) {
int length = attr.getLength();
for (int i = 0; i < length; i++) {
String val = attr.getValue(i).intern();
String localName = attr.getLocalName(i).intern();
p.add(new Property(val, localName));
}
}
public void startElement(ElementHandler<P, ?> parentElement, Attributes attr, ParseMonitor monitor) throws SAXException {
this.currentText = new StringBuilder();
this.attr = attr;
this.monitor = monitor;
this.parentElement = parentElement;
object = start();
}
protected T start() throws SAXException {
return null;
}
protected void end(String text) throws SAXException {
}
public void endElement() throws SAXException {
end(currentText.toString());
}
protected void text(char[] c, int start, int length) {
assert currentText != null;
currentText.append(c, start, length);
}
}
private Stack<ElementHandler> stack;
private ParseMonitor monitor;
public XMLParser(TopElementHandler rootHandler, ParseMonitor monitor) {
this.stack = new Stack<ElementHandler>();
this.monitor = monitor;
this.stack.push(rootHandler);
}
public void setDocumentLocator(Locator locator) {
if (monitor != null) {
monitor.setState("Starting parsing");
}
}
public void startDocument() throws SAXException {
}
public void endDocument() throws SAXException {
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
}
public void endPrefixMapping(String prefix) throws SAXException {
}
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
assert !stack.isEmpty();
ElementHandler parent = stack.peek();
if (parent != null) {
ElementHandler child = parent.getChild(qName);
if (child != null) {
child.startElement(parent, atts, monitor);
stack.push(child);
return;
}
}
stack.push(null);
}
public void endElement(String uri, String localName, String qName) throws SAXException {
ElementHandler handler = stack.pop();
if (handler != null) {
handler.endElement();
}
}
public void characters(char[] ch, int start, int length) throws SAXException {
assert !stack.isEmpty();
ElementHandler top = stack.peek();
if (top != null && top.needsText()) {
top.text(ch, start, length);
}
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
}
public void processingInstruction(String target, String data) throws SAXException {
}
public void skippedEntity(String name) throws SAXException {
}
}

View File

@ -0,0 +1,128 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.data.serialization;
import com.sun.hotspot.igv.data.Properties;
import com.sun.hotspot.igv.data.Property;
import java.io.IOException;
import java.io.Writer;
import java.util.Stack;
/**
*
* @author Thomas Wuerthinger
*/
public class XMLWriter extends Writer {
private Writer inner;
private Stack<String> elementStack;
public XMLWriter(Writer inner) {
this.inner = inner;
elementStack = new Stack<String>();
}
@Override
public void write(char[] arr) throws IOException {
write(arr, 0, arr.length);
}
public void write(char[] cbuf, int off, int len) throws IOException {
for (int i = off; i < off + len; i++) {
char c = cbuf[i];
if (c == '>') {
inner.write("&gt;");
} else if (c == '<') {
inner.write("&lt;");
} else if (c == '&') {
inner.write("&amp;");
} else {
inner.write(c);
}
}
}
public void flush() throws IOException {
inner.flush();
}
public void close() throws IOException {
inner.close();
}
public void endTag() throws IOException {
inner.write("</" + elementStack.pop() + ">\n");
}
public void startTag(String name) throws IOException {
inner.write("<" + name + ">\n");
elementStack.push(name);
}
public void simpleTag(String name) throws IOException {
inner.write("<" + name + "/>\n");
}
public void startTag(String name, Properties attributes) throws IOException {
inner.write("<" + name);
elementStack.push(name);
for (Property p : attributes.getProperties()) {
inner.write(" " + p.getName() + "=\"");
write(p.getValue().toCharArray());
inner.write("\"");
}
inner.write(">\n");
}
public void simpleTag(String name, Properties attributes) throws IOException {
inner.write("<" + name);
for (Property p : attributes.getProperties()) {
inner.write(" " + p.getName() + "=\"");
write(p.getValue().toCharArray());
inner.write("\"");
}
inner.write("/>\n");
}
public void writeProperties(Properties props) throws IOException {
if (props.getProperties().size() == 0) {
return;
}
startTag(Parser.PROPERTIES_ELEMENT);
for (Property p : props.getProperties()) {
startTag(Parser.PROPERTY_ELEMENT, new Properties(Parser.PROPERTY_NAME_PROPERTY, p.getName()));
this.write(p.getValue().toCharArray());
endTag();
}
endTag();
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data.services;
import com.sun.hotspot.igv.data.InputGraph;
/**
*
* @author Thomas Wuerthinger
*/
public interface GraphViewer {
public void view(InputGraph graph);
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.data.services;
import com.sun.hotspot.igv.data.Group;
/**
*
* @author Thomas Wuerthinger
*/
public interface GroupCallback {
public void started(Group g);
}

View File

@ -0,0 +1,39 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data.services;
import com.sun.hotspot.igv.data.Group;
import com.sun.hotspot.igv.data.Pair;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public interface GroupOrganizer {
public String getName();
public List<Pair<String, List<Group>>> organize(List<String> subFolders, List<Group> groups);
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.data.services;
import java.awt.Component;
/**
*
* @author Thomas Wuerthinger
*/
public interface GroupReceiver {
public Component init(GroupCallback callback);
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.data.services;
import com.sun.hotspot.igv.data.InputGraph;
import com.sun.hotspot.igv.data.InputNode;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public interface InputGraphProvider {
InputGraph getGraph();
void setSelectedNodes(Set<InputNode> nodes);
}

View File

@ -0,0 +1,38 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.data.services;
import com.sun.hotspot.igv.data.InputBlock;
import com.sun.hotspot.igv.data.InputGraph;
import java.util.Collection;
/**
*
* @author Thomas Wuerthinger
*/
public interface Scheduler {
public Collection<InputBlock> schedule(InputGraph graph);
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="com.sun.hotspot.igv.difference" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.sun.hotspot.igv.difference.</description>
<import file="nbproject/build-impl.xml"/>
</project>

View File

@ -0,0 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: com.sun.hotspot.igv.difference
OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/difference/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="com.sun.hotspot.igv.difference-impl" basedir="..">
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="netbeans.dest.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="You must define 'nbplatform.${nbplatform.active}.harness.dir'">
<condition>
<not>
<available file="${harness.dir}" type="dir"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=1657ecfe
build.xml.script.CRC32=03909051
build.xml.stylesheet.CRC32=79c3b980
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=1657ecfe
nbproject/build-impl.xml.script.CRC32=2208e770
nbproject/build-impl.xml.stylesheet.CRC32=deb65f65

View File

@ -0,0 +1,29 @@
# Deprecated since 5.0u1; for compatibility with 5.0:
disabled.clusters=\
apisupport1,\
harness,\
ide8,\
java1,\
nb6.0,\
profiler2
disabled.modules=\
org.netbeans.core.execution,\
org.netbeans.core.multiview,\
org.netbeans.core.output2,\
org.netbeans.modules.applemenu,\
org.netbeans.modules.autoupdate.services,\
org.netbeans.modules.autoupdate.ui,\
org.netbeans.modules.core.kit,\
org.netbeans.modules.favorites,\
org.netbeans.modules.javahelp,\
org.netbeans.modules.masterfs,\
org.netbeans.modules.options.keymap,\
org.netbeans.modules.sendopts,\
org.netbeans.modules.templates,\
org.openide.compat,\
org.openide.execution,\
org.openide.util.enumerations
enabled.clusters=\
platform7
nbjdk.active=JDK_1.6
nbplatform.active=default

View File

@ -0,0 +1,2 @@
javac.source=1.5
javac.compilerargs=-Xlint -Xlint:-serial

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>com.sun.hotspot.igv.difference</code-name-base>
<suite-component/>
<module-dependencies>
<dependency>
<code-name-base>com.sun.hotspot.igv.data</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages>
<package>com.sun.hotspot.igv.difference</package>
</public-packages>
</data>
</configuration>
</project>

View File

@ -0,0 +1 @@
suite.dir=${basedir}/..

View File

@ -0,0 +1,320 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.difference;
import com.sun.hotspot.igv.data.Group;
import com.sun.hotspot.igv.data.InputEdge;
import com.sun.hotspot.igv.data.InputGraph;
import com.sun.hotspot.igv.data.InputNode;
import com.sun.hotspot.igv.data.Property;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class Difference {
public static final String PROPERTY_STATE = "state";
public static final String VALUE_NEW = "new";
public static final String VALUE_CHANGED = "changed";
public static final String VALUE_SAME = "same";
public static final String VALUE_DELETED = "deleted";
public static final String OLD_PREFIX = "OLD_";
public static final String MAIN_PROPERTY = "name";
public static final double LIMIT = 100.0;
public static final String[] IGNORE_PROPERTIES = new String[]{"idx", "debug_idx"};
public static InputGraph createDiffGraph(InputGraph a, InputGraph b) {
if (a.getGroup() == b.getGroup()) {
return createDiffSameGroup(a, b);
} else {
return createDiff(a, b);
}
}
private static InputGraph createDiffSameGroup(InputGraph a, InputGraph b) {
Map<Integer, InputNode> keyMapB = new HashMap<Integer, InputNode>();
for (InputNode n : b.getNodes()) {
Integer key = n.getId();
assert !keyMapB.containsKey(key);
keyMapB.put(key, n);
}
Set<Pair> pairs = new HashSet<Pair>();
for (InputNode n : a.getNodes()) {
Integer key = n.getId();
if (keyMapB.containsKey(key)) {
InputNode nB = keyMapB.get(key);
pairs.add(new Pair(n, nB));
}
}
return createDiff(a, b, pairs);
}
private static InputGraph createDiff(InputGraph a, InputGraph b, Set<Pair> pairs) {
Group g = new Group();
g.setMethod(a.getGroup().getMethod());
g.setAssembly(a.getGroup().getAssembly());
g.getProperties().setProperty("name", "Difference");
InputGraph graph = new InputGraph(g, null);
graph.setName(a.getName() + ", " + b.getName());
graph.setIsDifferenceGraph(true);
Set<InputNode> nodesA = new HashSet<InputNode>(a.getNodes());
Set<InputNode> nodesB = new HashSet<InputNode>(b.getNodes());
Map<InputNode, InputNode> inputNodeMap = new HashMap<InputNode, InputNode>();
for (Pair p : pairs) {
InputNode n = p.getN1();
assert nodesA.contains(n);
InputNode nB = p.getN2();
assert nodesB.contains(nB);
nodesA.remove(n);
nodesB.remove(nB);
InputNode n2 = new InputNode(n);
inputNodeMap.put(n, n2);
inputNodeMap.put(nB, n2);
graph.addNode(n2);
markAsChanged(n2, n, nB);
}
for (InputNode n : nodesA) {
InputNode n2 = new InputNode(n);
graph.addNode(n2);
markAsNew(n2);
inputNodeMap.put(n, n2);
}
for (InputNode n : nodesB) {
InputNode n2 = new InputNode(n);
n2.setId(-n2.getId());
graph.addNode(n2);
markAsDeleted(n2);
inputNodeMap.put(n, n2);
}
Set<InputEdge> edgesA = a.getEdges();
Set<InputEdge> edgesB = b.getEdges();
Set<InputEdge> newEdges = new HashSet<InputEdge>();
for (InputEdge e : edgesA) {
int from = e.getFrom();
int to = e.getTo();
InputNode nodeFrom = inputNodeMap.get(a.getNode(from));
InputNode nodeTo = inputNodeMap.get(a.getNode(to));
char index = e.getToIndex();
InputEdge newEdge = new InputEdge(index, nodeFrom.getId(), nodeTo.getId());
if (!newEdges.contains(newEdge)) {
markAsNew(newEdge);
newEdges.add(newEdge);
graph.addEdge(newEdge);
}
}
for (InputEdge e : edgesB) {
int from = e.getFrom();
int to = e.getTo();
InputNode nodeFrom = inputNodeMap.get(b.getNode(from));
InputNode nodeTo = inputNodeMap.get(b.getNode(to));
char index = e.getToIndex();
InputEdge newEdge = new InputEdge(index, nodeFrom.getId(), nodeTo.getId());
if (!newEdges.contains(newEdge)) {
markAsDeleted(newEdge);
newEdges.add(newEdge);
graph.addEdge(newEdge);
} else {
newEdges.remove(newEdge);
graph.removeEdge(newEdge);
markAsSame(newEdge);
newEdges.add(newEdge);
graph.addEdge(newEdge);
}
}
g.addGraph(graph);
return graph;
}
private static class Pair {
private InputNode n1;
private InputNode n2;
public Pair(InputNode n1, InputNode n2) {
this.n1 = n1;
this.n2 = n2;
}
public double getValue() {
double result = 0.0;
for (Property p : n1.getProperties().getProperties()) {
double faktor = 1.0;
for (String forbidden : IGNORE_PROPERTIES) {
if (p.getName().equals(forbidden)) {
faktor = 0.1;
break;
}
}
String p2 = n2.getProperties().get(p.getName());
result += evaluate(p.getValue(), p2) * faktor;
}
return result;
}
private double evaluate(String p, String p2) {
if (p2 == null) {
return 1.0;
}
if (p.equals(p2)) {
return 0.0;
} else {
return (double) (Math.abs(p.length() - p2.length())) / p.length() + 0.5;
}
}
public InputNode getN1() {
return n1;
}
public InputNode getN2() {
return n2;
}
}
private static InputGraph createDiff(InputGraph a, InputGraph b) {
Set<InputNode> matched = new HashSet<InputNode>();
Set<Pair> pairs = new HashSet<Pair>();
for (InputNode n : a.getNodes()) {
String s = n.getProperties().get(MAIN_PROPERTY);
if (s == null) {
s = "";
}
for (InputNode n2 : b.getNodes()) {
String s2 = n2.getProperties().get(MAIN_PROPERTY);
if (s2 == null) {
s2 = "";
}
if (s.equals(s2)) {
Pair p = new Pair(n, n2);
pairs.add(p);
}
}
}
Set<Pair> selectedPairs = new HashSet<Pair>();
while (pairs.size() > 0) {
double min = Double.MAX_VALUE;
Pair minPair = null;
for (Pair p : pairs) {
double cur = p.getValue();
if (cur < min) {
minPair = p;
min = cur;
}
}
if (min > LIMIT) {
break;
} else {
selectedPairs.add(minPair);
Set<Pair> toRemove = new HashSet<Pair>();
for (Pair p : pairs) {
if (p.getN1() == minPair.getN1() || p.getN2() == minPair.getN2()) {
toRemove.add(p);
}
}
pairs.removeAll(toRemove);
}
}
return createDiff(a, b, selectedPairs);
}
private static void markAsNew(InputEdge e) {
e.setState(InputEdge.State.NEW);
}
private static void markAsDeleted(InputEdge e) {
e.setState(InputEdge.State.DELETED);
}
private static void markAsSame(InputEdge e) {
e.setState(InputEdge.State.SAME);
}
private static void markAsChanged(InputNode n, InputNode firstNode, InputNode otherNode) {
boolean difference = false;
for (Property p : otherNode.getProperties().getProperties()) {
String s = firstNode.getProperties().getProperty(p.getName());
if (!p.getValue().equals(s)) {
difference = true;
n.getProperties().add(new Property(OLD_PREFIX + p.getName(), p.getValue()));
}
}
for (Property p : firstNode.getProperties().getProperties()) {
String s = otherNode.getProperties().getProperty(p.getName());
if (s == null && p.getValue().length() > 0) {
difference = true;
n.getProperties().add(new Property(OLD_PREFIX + p.getName(), ""));
}
}
if (difference) {
n.getProperties().add(new Property(PROPERTY_STATE, VALUE_CHANGED));
} else {
n.getProperties().add(new Property(PROPERTY_STATE, VALUE_SAME));
}
}
private static void markAsDeleted(InputNode n) {
n.getProperties().add(new Property(PROPERTY_STATE, VALUE_DELETED));
}
private static void markAsNew(InputNode n) {
n.getProperties().add(new Property(PROPERTY_STATE, VALUE_NEW));
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="com.sun.hotspot.igv.filter" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.sun.hotspot.igv.filter.</description>
<import file="nbproject/build-impl.xml"/>
</project>

View File

@ -0,0 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: com.sun.hotspot.igv.filter
OpenIDE-Module-Layer: com/sun/hotspot/igv/filter/layer.xml
OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/filter/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="com.sun.hotspot.igv.filter-impl" basedir="..">
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="netbeans.dest.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="You must define 'nbplatform.${nbplatform.active}.harness.dir'">
<condition>
<not>
<available file="${harness.dir}" type="dir"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=7c032ebf
build.xml.script.CRC32=3b022a25
build.xml.stylesheet.CRC32=79c3b980
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=7c032ebf
nbproject/build-impl.xml.script.CRC32=26513f91
nbproject/build-impl.xml.stylesheet.CRC32=deb65f65

View File

@ -0,0 +1,29 @@
# Deprecated since 5.0u1; for compatibility with 5.0:
disabled.clusters=\
apisupport1,\
harness,\
ide8,\
java1,\
nb6.0,\
profiler2
disabled.modules=\
org.netbeans.core.execution,\
org.netbeans.core.multiview,\
org.netbeans.core.output2,\
org.netbeans.modules.applemenu,\
org.netbeans.modules.autoupdate.services,\
org.netbeans.modules.autoupdate.ui,\
org.netbeans.modules.core.kit,\
org.netbeans.modules.favorites,\
org.netbeans.modules.javahelp,\
org.netbeans.modules.masterfs,\
org.netbeans.modules.options.keymap,\
org.netbeans.modules.sendopts,\
org.netbeans.modules.templates,\
org.openide.compat,\
org.openide.execution,\
org.openide.util.enumerations
enabled.clusters=\
platform7
nbjdk.active=JDK_1.6
nbplatform.active=default

View File

@ -0,0 +1,2 @@
javac.source=1.5
javac.compilerargs=-Xlint -Xlint:-serial

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>com.sun.hotspot.igv.filter</code-name-base>
<suite-component/>
<module-dependencies>
<dependency>
<code-name-base>com.sun.hotspot.igv.data</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.hotspot.igv.graph</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.jdesktop.layout</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.4.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.dialogs</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.5.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.filesystems</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.3</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.nodes</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.2.0.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.9.0.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.windows</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.16</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages>
<package>com.sun.hotspot.igv.filter</package>
</public-packages>
</data>
</configuration>
</project>

View File

@ -0,0 +1 @@
suite.dir=${basedir}/..

View File

@ -0,0 +1 @@
com.sun.hotspot.igv.filter.JavaSE6ScriptEngine

View File

@ -0,0 +1,60 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.data.ChangedEvent;
import com.sun.hotspot.igv.data.Properties;
import org.openide.cookies.OpenCookie;
/**
*
* @author Thomas Wuerthinger
*/
public abstract class AbstractFilter implements Filter {
private ChangedEvent<Filter> changedEvent;
private Properties properties;
public AbstractFilter() {
changedEvent = new ChangedEvent<Filter>(this);
properties = new Properties();
}
public Properties getProperties() {
return properties;
}
public OpenCookie getEditor() {
return null;
}
public ChangedEvent<Filter> getChangedEvent() {
return changedEvent;
}
protected void fireChangedEvent() {
changedEvent.fire();
}
}

View File

@ -0,0 +1,11 @@
OpenIDE-Module-Name=Filter
jLabel1.text=Name\:
jLabel2.text=Source\:
nameTextField.text=
jButton1.text=OK
jButton2.text=Cancel
title=Edit Filter Dialog

View File

@ -0,0 +1,138 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Connection;
import com.sun.hotspot.igv.graph.Connection.ConnectionStyle;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.OutputSlot;
import com.sun.hotspot.igv.graph.Selector;
import com.sun.hotspot.igv.data.Properties;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class ColorFilter extends AbstractFilter {
private List<ColorRule> colorRules;
private String name;
public ColorFilter(String name) {
this.name = name;
colorRules = new ArrayList<ColorRule>();
}
public String getName() {
return name;
}
public void apply(Diagram diagram) {
Properties.PropertySelector<Figure> selector = new Properties.PropertySelector<Figure>(diagram.getFigures());
for (ColorRule rule : colorRules) {
if (rule.getSelector() != null) {
List<Figure> figures = rule.getSelector().selected(diagram);
for (Figure f : figures) {
applyRule(rule, f);
if (rule.getColor() != null) {
f.setColor(rule.getColor());
}
}
} else {
for (Figure f : diagram.getFigures()) {
applyRule(rule, f);
}
}
}
}
private void applyRule(ColorRule rule, Figure f) {
if (rule.getColor() != null) {
f.setColor(rule.getColor());
}
Color color = rule.getLineColor();
ConnectionStyle style = rule.getLineStyle();
for (OutputSlot s : f.getOutputSlots()) {
for (Connection c : s.getConnections()) {
if (color != null) {
c.setColor(color);
}
if (style != null) {
c.setStyle(style);
}
}
}
}
public void addRule(ColorRule r) {
colorRules.add(r);
}
public static class ColorRule {
private Color color;
private Color lineColor;
private Connection.ConnectionStyle lineStyle;
private Selector selector;
public ColorRule(Selector selector, Color c) {
this(selector, c, null, null);
}
public ColorRule(Selector selector, Color c, Color lineColor, Connection.ConnectionStyle lineStyle) {
this.selector = selector;
this.color = c;
this.lineColor = lineColor;
this.lineStyle = lineStyle;
}
public ColorRule(Color c) {
this(null, c);
}
public Color getColor() {
return color;
}
public Selector getSelector() {
return selector;
}
public Color getLineColor() {
return lineColor;
}
public Connection.ConnectionStyle getLineStyle() {
return lineStyle;
}
}
}

View File

@ -0,0 +1,194 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Connection;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.InputSlot;
import com.sun.hotspot.igv.graph.OutputSlot;
import com.sun.hotspot.igv.data.Properties;
import com.sun.hotspot.igv.data.Properties.PropertyMatcher;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class CombineFilter extends AbstractFilter {
private List<CombineRule> rules;
private String name;
public CombineFilter(String name) {
this.name = name;
rules = new ArrayList<CombineRule>();
}
public String getName() {
return name;
}
public void apply(Diagram diagram) {
Properties.PropertySelector<Figure> selector = new Properties.PropertySelector<Figure>(diagram.getFigures());
for (CombineRule r : rules) {
List<Figure> list = selector.selectMultiple(r.getFirstMatcher());
Set<Figure> figuresToRemove = new HashSet<Figure>();
for (Figure f : list) {
List<Figure> successors = new ArrayList<Figure>(f.getSuccessors());
if (r.isReversed()) {
if (successors.size() == 1) {
Figure succ = successors.get(0);
InputSlot slot = null;
for (InputSlot s : succ.getInputSlots()) {
for (Connection c : s.getConnections()) {
if (c.getOutputSlot().getFigure() == f) {
slot = s;
}
}
}
assert slot != null;
slot.setName(f.getProperties().get("dump_spec"));
if (f.getProperties().get("short_name") != null) {
slot.setShortName(f.getProperties().get("short_name"));
} else {
String s = f.getProperties().get("dump_spec");
if (s != null && s.length() <= 5) {
slot.setShortName(s);
}
}
for (InputSlot s : f.getInputSlots()) {
for (Connection c : s.getConnections()) {
Connection newConn = diagram.createConnection(slot, c.getOutputSlot());
newConn.setColor(c.getColor());
newConn.setStyle(c.getStyle());
}
}
figuresToRemove.add(f);
}
} else {
for (Figure succ : successors) {
if (succ.getPredecessors().size() == 1) {
if (succ.getProperties().selectSingle(r.getSecondMatcher()) != null && succ.getOutputSlots().size() == 1) {
OutputSlot oldSlot = null;
for (OutputSlot s : f.getOutputSlots()) {
for (Connection c : s.getConnections()) {
if (c.getInputSlot().getFigure() == succ) {
oldSlot = s;
}
}
}
assert oldSlot != null;
OutputSlot nextSlot = succ.getOutputSlots().get(0);
int pos = 0;
if (succ.getProperties().get("con") != null) {
pos = Integer.parseInt(succ.getProperties().get("con"));
}
OutputSlot slot = f.createOutputSlot(pos);
slot.setName(succ.getProperties().get("dump_spec"));
if (succ.getProperties().get("short_name") != null) {
slot.setShortName(succ.getProperties().get("short_name"));
} else {
String s = succ.getProperties().get("dump_spec");
if (s != null && s.length() <= 2) {
slot.setShortName(s);
} else {
String tmpName = succ.getProperties().get("name");
if (tmpName != null && tmpName.length() > 0) {
slot.setShortName(tmpName.substring(0, 1));
}
}
}
for (Connection c : nextSlot.getConnections()) {
Connection newConn = diagram.createConnection(c.getInputSlot(), slot);
newConn.setColor(c.getColor());
newConn.setStyle(c.getStyle());
}
figuresToRemove.add(succ);
if (oldSlot.getConnections().size() == 0) {
f.removeSlot(oldSlot);
}
}
}
}
}
}
diagram.removeAllFigures(figuresToRemove);
}
}
public void addRule(CombineRule combineRule) {
rules.add(combineRule);
}
public static class CombineRule {
private PropertyMatcher first;
private PropertyMatcher second;
private boolean reversed;
public CombineRule(PropertyMatcher first, PropertyMatcher second) {
this(first, second, false);
}
public CombineRule(PropertyMatcher first, PropertyMatcher second, boolean reversed) {
this.first = first;
this.second = second;
this.reversed = reversed;
}
public boolean isReversed() {
return reversed;
}
public PropertyMatcher getFirstMatcher() {
return first;
}
public PropertyMatcher getSecondMatcher() {
return second;
}
}
}

View File

@ -0,0 +1,106 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Connection;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.OutputSlot;
import com.sun.hotspot.igv.graph.Selector;
import com.sun.hotspot.igv.data.Properties;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class ConnectionFilter extends AbstractFilter {
private List<ConnectionStyleRule> connectionStyleRules;
private String name;
public ConnectionFilter(String name) {
this.name = name;
connectionStyleRules = new ArrayList<ConnectionStyleRule>();
}
public String getName() {
return name;
}
public void apply(Diagram diagram) {
Properties.PropertySelector<Figure> selector = new Properties.PropertySelector<Figure>(diagram.getFigures());
for (ConnectionStyleRule rule : connectionStyleRules) {
List<Figure> figures = null;
if (rule.getSelector() != null) {
figures = rule.getSelector().selected(diagram);
} else {
figures = diagram.getFigures();
}
for (Figure f : figures) {
for (OutputSlot os : f.getOutputSlots()) {
for (Connection c : os.getConnections()) {
if (figures.contains(c.getInputSlot().getFigure())) {
c.setStyle(rule.getLineStyle());
c.setColor(rule.getLineColor());
}
}
}
}
}
}
public void addRule(ConnectionStyleRule r) {
connectionStyleRules.add(r);
}
public static class ConnectionStyleRule {
private Color lineColor;
private Connection.ConnectionStyle lineStyle;
private Selector selector;
public ConnectionStyleRule(Selector selector, Color lineColor, Connection.ConnectionStyle lineStyle) {
this.selector = selector;
this.lineColor = lineColor;
this.lineStyle = lineStyle;
}
public Selector getSelector() {
return selector;
}
public Color getLineColor() {
return lineColor;
}
public Connection.ConnectionStyle getLineStyle() {
return lineStyle;
}
}
}

View File

@ -0,0 +1,159 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.data.Property;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.cookies.OpenCookie;
import org.openide.filesystems.Repository;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
/**
*
* @author Thomas Wuerthinger
*/
public class CustomFilter extends AbstractFilter {
public static final String JAVASCRIPT_HELPER_ID = "JavaScriptHelper";
private static ScriptEngineAbstraction engine;
private String code;
private String name;
public CustomFilter(String name, String code) {
this.name = name;
this.code = code;
getProperties().add(new Property("name", name));
}
public String getName() {
return name;
}
public String getCode() {
return code;
}
public void setName(String s) {
name = s;
fireChangedEvent();
}
public void setCode(String s) {
code = s;
fireChangedEvent();
}
@Override
public OpenCookie getEditor() {
return new OpenCookie() {
public void open() {
openInEditor();
}
};
}
public boolean openInEditor() {
EditFilterDialog dialog = new EditFilterDialog(CustomFilter.this);
dialog.setVisible(true);
return dialog.wasAccepted();
}
@Override
public String toString() {
return getName();
}
public static ScriptEngineAbstraction getEngine() {
if (engine == null) {
ScriptEngineAbstraction chosen = null;
try {
Collection<? extends ScriptEngineAbstraction> list = Lookup.getDefault().lookupAll(ScriptEngineAbstraction.class);
for (ScriptEngineAbstraction s : list) {
if (s.initialize(getJsHelperText())) {
if (chosen == null || !(chosen instanceof JavaSE6ScriptEngine)) {
chosen = s;
}
}
}
} catch (NoClassDefFoundError ncdfe) {
Logger.getLogger("global").log(Level.SEVERE, null, ncdfe);
}
if (chosen == null) {
NotifyDescriptor message = new NotifyDescriptor.Message("Could not find a scripting engine. Please make sure that the Rhino scripting engine is available. Otherwise filter cannot be used.", NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notifyLater(message);
chosen = new NullScriptEngine();
}
engine = chosen;
}
return engine;
}
private static String getJsHelperText() {
InputStream is = null;
StringBuilder sb = new StringBuilder("importPackage(Packages.com.sun.hotspot.igv.filter);importPackage(Packages.com.sun.hotspot.igv.graph);importPackage(Packages.com.sun.hotspot.igv.data);importPackage(Packages.com.sun.hotspot.igv.util);importPackage(java.awt);");
try {
FileSystem fs = Repository.getDefault().getDefaultFileSystem();
FileObject fo = fs.getRoot().getFileObject(JAVASCRIPT_HELPER_ID);
is = fo.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = r.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
} catch (IOException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
} finally {
try {
is.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
return sb.toString();
}
public void apply(Diagram d) {
getEngine().execute(d, code);
}
}

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.4" maxVersion="1.4" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="at/ssw/graphanalyzer/filter/Bundle.properties" key="title" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="sourceLabel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="nameLabel" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" pref="695" max="32767" attributes="1"/>
<Component id="nameTextField" alignment="0" pref="695" max="32767" attributes="1"/>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="okButton" min="-2" pref="76" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="nameLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="nameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="sourceLabel" min="-2" max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="337" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="16" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="okButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="sourceTextArea">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JTextField" name="nameTextField">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="at/ssw/graphanalyzer/coordinator/Bundle.properties" key="nameTextField.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="nameLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="at/ssw/graphanalyzer/filter/Bundle.properties" key="jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="sourceLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="at/ssw/graphanalyzer/filter/Bundle.properties" key="jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="at/ssw/graphanalyzer/filter/Bundle.properties" key="jButton1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonClicked,okButtonClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="at/ssw/graphanalyzer/filter/Bundle.properties" key="jButton2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonClicked"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,161 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.filter;
import org.openide.windows.WindowManager;
/**
*
* @author Thomas Wuerthinger
*/
public class EditFilterDialog extends javax.swing.JDialog {
private CustomFilter customFilter;
private boolean accepted;
/** Creates new form EditFilterDialog */
public EditFilterDialog(CustomFilter customFilter) {
super(WindowManager.getDefault().getMainWindow(), true);
this.customFilter = customFilter;
initComponents();
sourceTextArea.setText(customFilter.getCode());
nameTextField.setText(customFilter.getName());
}
public boolean wasAccepted() {
return accepted;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
sourceTextArea = new javax.swing.JTextArea();
nameTextField = new javax.swing.JTextField();
nameLabel = new javax.swing.JLabel();
sourceLabel = new javax.swing.JLabel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "title")); // NOI18N
setResizable(false);
sourceTextArea.setColumns(20);
sourceTextArea.setRows(5);
jScrollPane1.setViewportView(sourceTextArea);
nameTextField.setText("null");
nameLabel.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jLabel1.text")); // NOI18N
sourceLabel.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jLabel2.text")); // NOI18N
okButton.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jButton1.text")); // NOI18N
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonClicked(evt);
okButtonClicked(evt);
}
});
cancelButton.setText(org.openide.util.NbBundle.getMessage(EditFilterDialog.class, "jButton2.text")); // NOI18N
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonClicked(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(sourceLabel)
.add(nameLabel))
.add(25, 25, 25)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE)
.add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 695, Short.MAX_VALUE)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 76, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cancelButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(nameLabel)
.add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(sourceLabel)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 337, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 16, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(cancelButton)
.add(okButton))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void okButtonClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonClicked
this.customFilter.setName(this.nameTextField.getText());
this.customFilter.setCode(this.sourceTextArea.getText());
accepted = true;
setVisible(false);
}//GEN-LAST:event_okButtonClicked
private void cancelButtonClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonClicked
setVisible(false);
}//GEN-LAST:event_cancelButtonClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel nameLabel;
private javax.swing.JTextField nameTextField;
private javax.swing.JButton okButton;
private javax.swing.JLabel sourceLabel;
private javax.swing.JTextArea sourceTextArea;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,45 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.data.ChangedEvent;
import com.sun.hotspot.igv.data.ChangedEventProvider;
import com.sun.hotspot.igv.data.Properties;
import com.sun.hotspot.igv.graph.Diagram;
import org.openide.cookies.OpenCookie;
/**
*
* @author Thomas Wuerthinger
*/
public interface Filter extends Properties.Provider, ChangedEventProvider<Filter> {
public String getName();
public void apply(Diagram d);
OpenCookie getEditor();
ChangedEvent<Filter> getChangedEvent();
}

View File

@ -0,0 +1,155 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.data.ChangedEvent;
import com.sun.hotspot.igv.data.ChangedEventProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class FilterChain implements ChangedEventProvider<FilterChain> {
private List<Filter> filters;
private transient ChangedEvent<FilterChain> changedEvent;
private boolean fireEvents;
public FilterChain() {
filters = new ArrayList<Filter>();
changedEvent = new ChangedEvent<FilterChain>(this);
this.fireEvents = true;
}
public FilterChain(FilterChain f) {
this.filters = new ArrayList<Filter>(f.filters);
changedEvent = new ChangedEvent<FilterChain>(this);
this.fireEvents = true;
}
public ChangedEvent<FilterChain> getChangedEvent() {
return changedEvent;
}
public Filter getFilterAt(int index) {
assert index >= 0 && index < filters.size();
return filters.get(index);
}
public void apply(Diagram d) {
for (Filter f : filters) {
f.apply(d);
}
}
public void apply(Diagram d, FilterChain sequence) {
List<Filter> applied = new ArrayList<Filter>();
for (Filter f : sequence.getFilters()) {
if (filters.contains(f)) {
f.apply(d);
applied.add(f);
}
}
for (Filter f : filters) {
if (!applied.contains(f)) {
f.apply(d);
}
}
}
public void beginAtomic() {
this.fireEvents = false;
}
public void endAtomic() {
this.fireEvents = true;
changedEvent.fire();
}
public void addFilter(Filter filter) {
assert filter != null;
filters.add(filter);
if (fireEvents) {
changedEvent.fire();
}
}
public void addFilterSameSequence(Filter filter) {
assert filter != null;
filters.add(filter);
if (fireEvents) {
changedEvent.fire();
}
}
public boolean containsFilter(Filter filter) {
return filters.contains(filter);
}
public void removeFilter(Filter filter) {
assert filters.contains(filter);
filters.remove(filter);
if (fireEvents) {
changedEvent.fire();
}
}
public void moveFilterUp(Filter filter) {
assert filters.contains(filter);
int index = filters.indexOf(filter);
if (index != 0) {
filters.remove(index);
filters.add(index - 1, filter);
}
if (fireEvents) {
changedEvent.fire();
}
}
public void moveFilterDown(Filter filter) {
assert filters.contains(filter);
int index = filters.indexOf(filter);
if (index != filters.size() - 1) {
filters.remove(index);
filters.add(index + 1, filter);
}
if (fireEvents) {
changedEvent.fire();
}
}
public List<Filter> getFilters() {
return Collections.unmodifiableList(filters);
}
public void clear() {
filters.clear();
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
/**
*
* @author Thomas Wuerthinger
*/
public interface FilterChainProvider {
public FilterChain getFilterChain();
public FilterChain getSequence();
}

View File

@ -0,0 +1,82 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class FilterSetting {
private Set<Filter> filters;
private String name;
public FilterSetting() {
this(null);
}
public FilterSetting(String name) {
this.name = name;
filters = new HashSet<Filter>();
}
public Set<Filter> getFilters() {
return Collections.unmodifiableSet(filters);
}
public void addFilter(Filter f) {
assert !filters.contains(f);
filters.add(f);
}
public void removeFilter(Filter f) {
assert filters.contains(f);
filters.remove(f);
}
public boolean containsFilter(Filter f) {
return filters.contains(f);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getFilterCount() {
return filters.size();
}
@Override
public String toString() {
return getName();
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Diagram;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.openide.util.Exceptions;
/**
*
* @author Thomas Wuerthinger
*/
public class JavaSE6ScriptEngine implements ScriptEngineAbstraction {
private ScriptEngine engine;
private Bindings bindings;
public boolean initialize(String jsHelperText) {
try {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine e = sem.getEngineByName("ECMAScript");
engine = e;
e.eval(jsHelperText);
Bindings b = e.getContext().getBindings(ScriptContext.ENGINE_SCOPE);
b.put("IO", System.out);
bindings = b;
return true;
} catch (Exception e) {
return false;
}
}
public void execute(Diagram d, String code) {
try {
Bindings b = bindings;
b.put("graph", d);
engine.eval(code, b);
} catch (ScriptException ex) {
Exceptions.printStackTrace(ex);
}
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Diagram;
/**
*
* @author Thomas Wuerthinger
*/
public class NullScriptEngine implements ScriptEngineAbstraction {
public boolean initialize(String jsHelperText) {
return true;
}
public void execute(Diagram d, String code) {
}
}

View File

@ -0,0 +1,132 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.InputSlot;
import com.sun.hotspot.igv.graph.Selector;
import com.sun.hotspot.igv.data.Properties;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author Thomas Wuerthinger
*/
public class RemoveFilter extends AbstractFilter {
private List<RemoveRule> rules;
private String name;
public RemoveFilter(String name) {
this.name = name;
rules = new ArrayList<RemoveRule>();
}
public String getName() {
return name;
}
public void apply(Diagram diagram) {
for (RemoveRule r : rules) {
List<Figure> list = r.getSelector().selected(diagram);
Set<Figure> figuresToRemove = new HashSet<Figure>();
List<Figure> protectedFigures = null;
if (r.getRemoveAllWithoutPredecessor()) {
protectedFigures = diagram.getRootFigures();
}
for (Figure f : list) {
if (r.getRemoveOnlyInputs()) {
List<InputSlot> inputSlots = new ArrayList<InputSlot>();
for (InputSlot is : f.getInputSlots()) {
inputSlots.add(is);
}
for (InputSlot is : inputSlots) {
f.removeSlot(is);
}
f.createInputSlot();
} else {
figuresToRemove.add(f);
}
}
if (r.getRemoveAllWithoutPredecessor()) {
boolean progress = true;
while (progress) {
List<Figure> rootFigures = diagram.getRootFigures();
progress = false;
for (Figure f : rootFigures) {
if (!protectedFigures.contains(f)) {
figuresToRemove.add(f);
progress = true;
}
}
}
}
diagram.removeAllFigures(figuresToRemove);
}
}
public void addRule(RemoveRule rule) {
rules.add(rule);
}
public static class RemoveRule {
private Selector selector;
private boolean removeAllWithoutPredecessor;
private boolean removeOnlyInputs;
public RemoveRule(Selector selector, boolean b) {
this(selector, b, false);
}
public RemoveRule(Selector selector, boolean removeAllWithoutPredecessor, boolean removeOnlyInputs) {
this.selector = selector;
this.removeOnlyInputs = removeOnlyInputs;
this.removeAllWithoutPredecessor = removeAllWithoutPredecessor;
}
public Selector getSelector() {
return selector;
}
public boolean getRemoveOnlyInputs() {
return removeOnlyInputs;
}
public boolean getRemoveAllWithoutPredecessor() {
return removeAllWithoutPredecessor;
}
}
}

View File

@ -0,0 +1,143 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Connection;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.InputSlot;
import com.sun.hotspot.igv.graph.OutputSlot;
import com.sun.hotspot.igv.graph.Selector;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class RemoveInputsFilter extends AbstractFilter {
private List<RemoveInputsRule> rules;
private String name;
public RemoveInputsFilter(String name) {
this.name = name;
rules = new ArrayList<RemoveInputsRule>();
}
public String getName() {
return name;
}
public void apply(Diagram diagram) {
for (RemoveInputsRule r : rules) {
List<Figure> list = r.getSelector().selected(diagram);
for (Figure f : list) {
int z = 0;
List<InputSlot> last = new ArrayList<InputSlot>();
for (InputSlot is : f.getInputSlots()) {
if (z >= r.getStartingIndex() && z <= r.getEndIndex() && is.getConnections().size() > 0) {
StringBuilder sb = new StringBuilder();
List<Connection> conns = is.getConnections();
for (int i = 0; i < conns.size(); i++) {
Connection c = conns.get(i);
OutputSlot os = c.getOutputSlot();
Figure pred = os.getFigure();
if (i != 0) {
sb.append("<BR>");
}
sb.append(pred.getLines()[0]);
}
is.removeAllConnections();
is.setShortName("X");
is.setName(sb.toString());
last.add(is);
} else {
last.clear();
}
z++;
}
if (last.size() > 3) {
InputSlot first = last.get(0);
first.setShortName("XX");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < last.size(); i++) {
InputSlot is2 = last.get(i);
if (i != 0) {
sb.append("<BR>");
}
sb.append(is2.getName());
}
first.setName(sb.toString());
for (int i = 1; i < last.size(); i++) {
f.removeSlot(last.get(i));
}
}
}
}
}
public void addRule(RemoveInputsRule rule) {
rules.add(rule);
}
public static class RemoveInputsRule {
private Selector selector;
private int startingIndex;
private int endIndex;
public RemoveInputsRule(Selector selector) {
this(selector, 0);
}
public RemoveInputsRule(Selector selector, int startIndex) {
this(selector, startIndex, Integer.MAX_VALUE);
}
public RemoveInputsRule(Selector selector, int startIndex, int endIndex) {
this.startingIndex = startIndex;
this.endIndex = endIndex;
this.selector = selector;
}
public int getStartingIndex() {
return startingIndex;
}
public int getEndIndex() {
return endIndex;
}
public Selector getSelector() {
return selector;
}
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Connection;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.InputSlot;
import com.sun.hotspot.igv.graph.OutputSlot;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class RemoveSelfLoopsFilter extends AbstractFilter {
private String name;
/** Creates a new instance of RemoveSelfLoops */
public RemoveSelfLoopsFilter(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void apply(Diagram d) {
for (Figure f : d.getFigures()) {
for (InputSlot is : f.getInputSlots()) {
List<Connection> toRemove = new ArrayList<Connection>();
for (Connection c : is.getConnections()) {
if (c.getOutputSlot().getFigure() == f) {
toRemove.add(c);
}
}
for (Connection c : toRemove) {
c.remove();
OutputSlot os = c.getOutputSlot();
if (os.getConnections().size() == 0) {
f.removeSlot(os);
}
c.getInputSlot().setShortName("O");
c.getInputSlot().setName("Self Loop");
}
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Diagram;
/**
*
* @author Thomas Wuerthinger
*/
public interface ScriptEngineAbstraction {
public boolean initialize(String jsHelperText);
public void execute(Diagram d, String code);
}

View File

@ -0,0 +1,70 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filter;
import com.sun.hotspot.igv.graph.Connection;
import com.sun.hotspot.igv.graph.Diagram;
import com.sun.hotspot.igv.graph.Figure;
import com.sun.hotspot.igv.graph.InputSlot;
import com.sun.hotspot.igv.graph.OutputSlot;
import com.sun.hotspot.igv.graph.Selector;
import java.util.List;
/**
*
* @author Thomas Wuerthinger
*/
public class SplitFilter extends AbstractFilter {
private String name;
private Selector selector;
public SplitFilter(String name, Selector selector) {
this.name = name;
this.selector = selector;
}
public String getName() {
return name;
}
public void apply(Diagram d) {
List<Figure> list = selector.selected(d);
for (Figure f : list) {
for (OutputSlot os : f.getOutputSlots()) {
for (Connection c : os.getConnections()) {
InputSlot is = c.getInputSlot();
is.setName(f.getProperties().getProperty("dump_spec"));
String s = f.getProperties().getProperty("short_name");
if (s != null) {
is.setShortName(s);
}
}
}
d.removeFigure(f);
}
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
/**
*
* @author Thomas Wuerthinger
*/
function colorize(property, regexp, color) {
var f = new ColorFilter("");
f.addRule(new ColorFilter.ColorRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), color));
f.apply(graph);
}
function remove(property, regexp) {
var f = new RemoveFilter("");
f.addRule(new RemoveFilter.RemoveRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), false, false));
f.apply(graph);
}
function split(property, regexp) {
var f = new SplitFilter("", new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)));
f.apply(graph);
}
function removeInputs(property, regexp, from, to) {
var f = new RemoveInputsFilter("");
if(from == undefined && to == undefined) {
f.addRule(new RemoveInputsFilter.RemoveInputsRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp))));
} else if(to == undefined) {
f.addRule(new RemoveInputsFilter.RemoveInputsRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), from));
} else {
f.addRule(new RemoveInputsFilter.RemoveInputsRule(new MatcherSelector(new Properties.RegexpPropertyMatcher(property, regexp)), from, to));
}
f.apply(graph);
}
var black = Color.black;
var blue = Color.blue;
var cyan = Color.cyan;
var darkGray = Color.darkGray;
var gray = Color.gray;
var green = Color.green;
var lightGray = Color.lightGray;
var magenta = Color.magenta;
var orange = Color.orange;
var pink = Color.pink
var red = Color.red;
var yellow = Color.yellow;
var white = Color.white;

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
<filesystem>
<file name="JavaScriptHelper" url="helper.js"/>
</filesystem>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="com.sun.hotspot.igv.filterwindow" default="netbeans" basedir=".">
<description>Builds, tests, and runs the project com.sun.hotspot.igv.filterwindow.</description>
<import file="nbproject/build-impl.xml"/>
</project>

View File

@ -0,0 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: com.sun.hotspot.igv.filterwindow
OpenIDE-Module-Layer: com/sun/hotspot/igv/filterwindow/layer.xml
OpenIDE-Module-Localizing-Bundle: com/sun/hotspot/igv/filterwindow/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
-->
<project name="com.sun.hotspot.igv.filterwindow-impl" basedir="..">
<property file="nbproject/private/suite-private.properties"/>
<property file="nbproject/suite.properties"/>
<fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail>
<property file="${suite.dir}/nbproject/private/platform-private.properties"/>
<property file="${suite.dir}/nbproject/platform.properties"/>
<macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
<property file="${user.properties.file}"/>
<nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<nbmproject2:property name="netbeans.dest.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
<fail message="You must define 'nbplatform.${nbplatform.active}.harness.dir'">
<condition>
<not>
<available file="${harness.dir}" type="dir"/>
</not>
</condition>
</fail>
<import file="${harness.dir}/build.xml"/>
</project>

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=401b2654
build.xml.script.CRC32=9c158403
build.xml.stylesheet.CRC32=79c3b980
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=401b2654
nbproject/build-impl.xml.script.CRC32=19fb08e0
nbproject/build-impl.xml.stylesheet.CRC32=deb65f65

View File

@ -0,0 +1,2 @@
javac.source=1.5
javac.compilerargs=-Xlint -Xlint:-serial

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>com.sun.hotspot.igv.filterwindow</code-name-base>
<suite-component/>
<module-dependencies>
<dependency>
<code-name-base>com.sun.hotspot.igv.data</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.hotspot.igv.filter</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.hotspot.igv.graph</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>com.sun.hotspot.igv.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.actions</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.6.1.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.dialogs</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.5.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.explorer</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.12.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.filesystems</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.3.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.loaders</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.7.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.nodes</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.2.1.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.10.1.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.windows</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>6.18.1</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<public-packages/>
</data>
</configuration>
</project>

View File

@ -0,0 +1 @@
suite.dir=${basedir}/..

View File

@ -0,0 +1 @@
com.sun.hotspot.igv.filterwindow.FilterChainProviderImplementation

View File

@ -0,0 +1,3 @@
OpenIDE-Module-Name=FilterWindow
CTL_FilterTopComponent=Filter Window
HINT_FilterTopComponent=This is a Filter window

View File

@ -0,0 +1,52 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import javax.swing.JList;
import org.openide.explorer.view.ListView;
import org.openide.explorer.view.NodeListModel;
/**
*
* @author Thomas Wuerthinger
*/
public class CheckListView extends ListView {
@Override
public void showSelection(int[] indices) {
super.showSelection(indices);
}
@Override
protected NodeListModel createModel() {
return new CheckNodeListModel();
}
@Override
protected JList createList() {
JList tmpList = super.createList();
tmpList.setCellRenderer(new CheckRenderer(tmpList));
return tmpList;
}
}

View File

@ -0,0 +1,70 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import com.sun.hotspot.igv.data.ChangedEvent;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.Lookup;
/**
*
* @author Thomas Wuerthinger
*/
public class CheckNode extends AbstractNode {
private ChangedEvent<CheckNode> selectionChangedEvent;
public boolean selected;
public boolean enabled;
public CheckNode(Children c, Lookup lookup) {
super(c, lookup);
selectionChangedEvent = new ChangedEvent<CheckNode>(this);
selected = false;
enabled = true;
}
public ChangedEvent<CheckNode> getSelectionChangedEvent() {
return selectionChangedEvent;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean b) {
if (b != selected) {
selected = b;
selectionChangedEvent.fire();
}
}
public void setEnabled(boolean b) {
enabled = b;
}
public boolean isEnabled() {
return enabled;
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import org.openide.explorer.view.NodeListModel;
import org.openide.nodes.Node;
/**
*
* @author Thomas Wuerthinger
*/
public class CheckNodeListModel extends NodeListModel {
private Node rootNode;
@Override
public void setNode(Node rootNode) {
this.rootNode = rootNode;
super.setNode(rootNode);
}
public CheckNode getCheckNodeAt(int index) {
return (CheckNode) rootNode.getChildren().getNodes()[index];
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
/**
* @author Thomas Wuerthinger
*/
public class CheckRenderer extends JCheckBox implements ListCellRenderer {
private JList list;
private Color startBackground;
public CheckRenderer(final JList list) {
this.list = list;
list.addMouseListener(
new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int index = list.locationToIndex(e.getPoint());
Point p2 = list.indexToLocation(index);
Rectangle r = new Rectangle(p2.x, p2.y, getPreferredSize().height, getPreferredSize().height);
if (r.contains(e.getPoint())) {
CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index);
node.setSelected(!node.isSelected());
list.repaint();
e.consume();
}
}
});
this.setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height - 5));
startBackground = this.getBackground();
}
public Component getListCellRendererComponent(final JList list, Object value, final int index, boolean isSelected, boolean cellHasFocus) {
setText(value.toString());
CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index);
this.setSelected(node.isSelected());
this.setEnabled(list.isEnabled());
if (isSelected && list.hasFocus()) {
this.setBackground(list.getSelectionBackground());
this.setForeground(list.getSelectionForeground());
} else if (isSelected) {
assert !list.hasFocus();
this.setBackground(startBackground);
this.setForeground(list.getForeground());
} else {
this.setBackground(list.getBackground());
this.setForeground(list.getForeground());
}
return this;
}
}

View File

@ -0,0 +1,42 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import com.sun.hotspot.igv.filter.FilterChain;
import com.sun.hotspot.igv.filter.FilterChainProvider;
/**
*
* @author Thomas Wuerthinger
*/
public class FilterChainProviderImplementation implements FilterChainProvider {
public FilterChain getFilterChain() {
return FilterTopComponent.findInstance().getFilterChain();
}
public FilterChain getSequence() {
return FilterTopComponent.findInstance().getSequence();
}
}

View File

@ -0,0 +1,112 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import com.sun.hotspot.igv.filterwindow.actions.MoveFilterDownAction;
import com.sun.hotspot.igv.filterwindow.actions.MoveFilterUpAction;
import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterAction;
import com.sun.hotspot.igv.filter.Filter;
import com.sun.hotspot.igv.filter.FilterChain;
import com.sun.hotspot.igv.data.ChangedListener;
import com.sun.hotspot.igv.util.PropertiesSheet;
import javax.swing.Action;
import org.openide.actions.OpenAction;
import org.openide.nodes.Children;
import org.openide.nodes.Sheet;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.Utilities;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
/**
*
* @author Thomas Wuerthinger
*/
public class FilterNode extends CheckNode implements LookupListener, ChangedListener<FilterTopComponent> {
private Filter filter;
private Lookup.Result result;
public FilterNode(Filter filter) {
this(filter, new InstanceContent());
}
private FilterNode(Filter filter, InstanceContent content) {
super(Children.LEAF, new AbstractLookup(content));
content.add(filter);
content.add(filter.getEditor());
this.filter = filter;
filter.getChangedEvent().addListener(new ChangedListener<Filter>() {
public void changed(Filter source) {
update();
}
});
update();
Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
FilterTopComponent.findInstance().getFilterSettingsChangedEvent().addListener(this);
resultChanged(null);
}
private void update() {
this.setDisplayName(filter.getName());
}
public Filter getFilter() {
return filter;
}
@Override
protected Sheet createSheet() {
Sheet s = super.createSheet();
PropertiesSheet.initializeSheet(getFilter().getProperties(), s);
return s;
}
@Override
public Action[] getActions(boolean b) {
return new Action[]{(Action) OpenAction.findObject(OpenAction.class, true), (Action) MoveFilterUpAction.findObject(MoveFilterUpAction.class, true), (Action) MoveFilterDownAction.findObject(MoveFilterDownAction.class, true), (Action) RemoveFilterAction.findObject(RemoveFilterAction.class, true)};
}
@Override
public Action getPreferredAction() {
return OpenAction.get(OpenAction.class).createContextAwareInstance(Utilities.actionsGlobalContext());
}
public void resultChanged(LookupEvent lookupEvent) {
changed(FilterTopComponent.findInstance());
}
public void changed(FilterTopComponent source) {
setSelected(source.getFilterChain().containsFilter(filter));
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
</Form>

View File

@ -0,0 +1,689 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package com.sun.hotspot.igv.filterwindow;
import com.sun.hotspot.igv.filterwindow.actions.MoveFilterDownAction;
import com.sun.hotspot.igv.filterwindow.actions.MoveFilterUpAction;
import com.sun.hotspot.igv.filterwindow.actions.NewFilterAction;
import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterAction;
import com.sun.hotspot.igv.filterwindow.actions.RemoveFilterSettingsAction;
import com.sun.hotspot.igv.filterwindow.actions.SaveFilterSettingsAction;
import com.sun.hotspot.igv.filter.CustomFilter;
import com.sun.hotspot.igv.filter.Filter;
import com.sun.hotspot.igv.filter.FilterChain;
import com.sun.hotspot.igv.filter.FilterSetting;
import com.sun.hotspot.igv.data.ChangedEvent;
import com.sun.hotspot.igv.data.ChangedListener;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.JComboBox;
import javax.swing.UIManager;
import javax.swing.border.Border;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.NotifyDescriptor;
import org.openide.awt.ToolbarPool;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.awt.Toolbar;
import org.openide.filesystems.FileLock;
import org.openide.util.actions.SystemAction;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.openide.filesystems.Repository;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileObject;
/**
*
* @author Thomas Wuerthinger
*/
public final class FilterTopComponent extends TopComponent implements LookupListener, ExplorerManager.Provider {
private static FilterTopComponent instance;
public static final String FOLDER_ID = "Filters";
public static final String AFTER_ID = "after";
public static final String ENABLED_ID = "enabled";
public static final String PREFERRED_ID = "FilterTopComponent";
private CheckListView view;
private ExplorerManager manager;
private FilterChain filterChain;
private FilterChain sequence;
private Lookup.Result result;
private JComboBox comboBox;
private List<FilterSetting> filterSettings;
private FilterSetting customFilterSetting = new FilterSetting("-- Custom --");
private ChangedEvent<FilterTopComponent> filterSettingsChangedEvent;
private ActionListener comboBoxActionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
comboBoxSelectionChanged();
}
};
public ChangedEvent<FilterTopComponent> getFilterSettingsChangedEvent() {
return filterSettingsChangedEvent;
}
public FilterChain getSequence() {
return sequence;
}
public void updateSelection() {
Node[] nodes = this.getExplorerManager().getSelectedNodes();
int[] arr = new int[nodes.length];
for (int i = 0; i < nodes.length; i++) {
int index = sequence.getFilters().indexOf(((FilterNode) nodes[i]).getFilter());
arr[i] = index;
}
view.showSelection(arr);
}
private void comboBoxSelectionChanged() {
Object o = comboBox.getSelectedItem();
if (o == null) {
return;
}
assert o instanceof FilterSetting;
FilterSetting s = (FilterSetting) o;
if (s != customFilterSetting) {
FilterChain chain = getFilterChain();
chain.beginAtomic();
List<Filter> toRemove = new ArrayList<Filter>();
for (Filter f : chain.getFilters()) {
if (!s.containsFilter(f)) {
toRemove.add(f);
}
}
for (Filter f : toRemove) {
chain.removeFilter(f);
}
for (Filter f : s.getFilters()) {
if (!chain.containsFilter(f)) {
chain.addFilter(f);
}
}
chain.endAtomic();
filterSettingsChangedEvent.fire();
} else {
this.updateComboBoxSelection();
}
SystemAction.get(RemoveFilterSettingsAction.class).setEnabled(comboBox.getSelectedItem() != this.customFilterSetting);
SystemAction.get(SaveFilterSettingsAction.class).setEnabled(comboBox.getSelectedItem() == this.customFilterSetting);
}
private void updateComboBox() {
comboBox.removeAllItems();
comboBox.addItem(customFilterSetting);
for (FilterSetting s : filterSettings) {
comboBox.addItem(s);
}
this.updateComboBoxSelection();
}
public void addFilterSetting() {
NotifyDescriptor.InputLine l = new NotifyDescriptor.InputLine("Enter a name:", "Filter");
if (DialogDisplayer.getDefault().notify(l) == NotifyDescriptor.OK_OPTION) {
String name = l.getInputText();
FilterSetting toRemove = null;
for (FilterSetting s : filterSettings) {
if (s.getName().equals(name)) {
NotifyDescriptor.Confirmation conf = new NotifyDescriptor.Confirmation("Filter \"" + name + "\" already exists, to you want to overwrite?", "Filter");
if (DialogDisplayer.getDefault().notify(conf) == NotifyDescriptor.YES_OPTION) {
toRemove = s;
break;
} else {
return;
}
}
}
if (toRemove != null) {
filterSettings.remove(toRemove);
}
FilterSetting setting = createFilterSetting(name);
filterSettings.add(setting);
// Sort alphabetically
Collections.sort(filterSettings, new Comparator<FilterSetting>() {
public int compare(FilterSetting o1, FilterSetting o2) {
return o1.getName().compareTo(o2.getName());
}
});
updateComboBox();
}
}
public boolean canRemoveFilterSetting() {
return comboBox.getSelectedItem() != customFilterSetting;
}
public void removeFilterSetting() {
if (canRemoveFilterSetting()) {
Object o = comboBox.getSelectedItem();
assert o instanceof FilterSetting;
FilterSetting f = (FilterSetting) o;
assert f != customFilterSetting;
assert filterSettings.contains(f);
NotifyDescriptor.Confirmation l = new NotifyDescriptor.Confirmation("Do you really want to remove filter \"" + f + "\"?", "Filter");
if (DialogDisplayer.getDefault().notify(l) == NotifyDescriptor.YES_OPTION) {
filterSettings.remove(f);
updateComboBox();
}
}
}
private FilterSetting createFilterSetting(String name) {
FilterSetting s = new FilterSetting(name);
FilterChain chain = this.getFilterChain();
for (Filter f : chain.getFilters()) {
s.addFilter(f);
}
return s;
}
private void updateComboBoxSelection() {
List<Filter> filters = this.getFilterChain().getFilters();
boolean found = false;
for (FilterSetting s : filterSettings) {
if (s.getFilterCount() == filters.size()) {
boolean ok = true;
for (Filter f : filters) {
if (!s.containsFilter(f)) {
ok = false;
}
}
if (ok) {
if (comboBox.getSelectedItem() != s) {
comboBox.setSelectedItem(s);
}
found = true;
break;
}
}
}
if (!found && comboBox.getSelectedItem() != customFilterSetting) {
comboBox.setSelectedItem(customFilterSetting);
}
}
private class FilterChildren extends Children.Keys implements ChangedListener<CheckNode> {
//private Node[] oldSelection;
//private ArrayList<Node> newSelection;
private HashMap<Object, Node> nodeHash = new HashMap<Object, Node>();
protected Node[] createNodes(Object object) {
if (nodeHash.containsKey(object)) {
return new Node[]{nodeHash.get(object)};
}
assert object instanceof Filter;
Filter filter = (Filter) object;
com.sun.hotspot.igv.filterwindow.FilterNode node = new com.sun.hotspot.igv.filterwindow.FilterNode(filter);
node.getSelectionChangedEvent().addListener(this);
nodeHash.put(object, node);
return new Node[]{node};
}
public FilterChildren() {
sequence.getChangedEvent().addListener(new ChangedListener<FilterChain>() {
public void changed(FilterChain source) {
addNotify();
}
});
setBefore(false);
}
protected void addNotify() {
setKeys(sequence.getFilters());
updateSelection();
}
public void changed(CheckNode source) {
FilterNode node = (FilterNode) source;
Filter f = node.getFilter();
FilterChain chain = getFilterChain();
if (node.isSelected()) {
if (!chain.containsFilter(f)) {
chain.addFilter(f);
}
} else {
if (chain.containsFilter(f)) {
chain.removeFilter(f);
}
}
view.revalidate();
view.repaint();
updateComboBoxSelection();
}
}
public FilterChain getFilterChain() {
return filterChain;/*
EditorTopComponent tc = EditorTopComponent.getActive();
if (tc == null) {
return filterChain;
}
return tc.getFilterChain();*/
}
private FilterTopComponent() {
filterSettingsChangedEvent = new ChangedEvent<FilterTopComponent>(this);
initComponents();
setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent"));
setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent"));
// setIcon(Utilities.loadImage(ICON_PATH, true));
sequence = new FilterChain();
filterChain = new FilterChain();
initFilters();
manager = new ExplorerManager();
manager.setRootContext(new AbstractNode(new FilterChildren()));
associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
view = new CheckListView();
ToolbarPool.getDefault().setPreferredIconSize(16);
Toolbar toolBar = new Toolbar();
Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
toolBar.setBorder(b);
comboBox = new JComboBox();
toolBar.add(comboBox);
this.add(toolBar, BorderLayout.NORTH);
toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class));
toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class));
toolBar.addSeparator();
toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup()));
toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup()));
toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup()));
toolBar.add(NewFilterAction.get(NewFilterAction.class));
this.add(view, BorderLayout.CENTER);
filterSettings = new ArrayList<FilterSetting>();
updateComboBox();
comboBox.addActionListener(comboBoxActionListener);
setChain(filterChain);
}
public void newFilter() {
CustomFilter cf = new CustomFilter("My custom filter", "");
if (cf.openInEditor()) {
sequence.addFilter(cf);
FileObject fo = getFileObject(cf);
FilterChangedListener listener = new FilterChangedListener(fo, cf);
listener.changed(cf);
cf.getChangedEvent().addListener(listener);
}
}
public void removeFilter(Filter f) {
com.sun.hotspot.igv.filter.CustomFilter cf = (com.sun.hotspot.igv.filter.CustomFilter) f;
sequence.removeFilter(cf);
try {
getFileObject(cf).delete();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
private static class FilterChangedListener implements ChangedListener<Filter> {
private FileObject fileObject;
private CustomFilter filter;
public FilterChangedListener(FileObject fo, CustomFilter cf) {
fileObject = fo;
filter = cf;
}
public void changed(Filter source) {
try {
if (!fileObject.getName().equals(filter.getName())) {
FileLock lock = fileObject.lock();
fileObject.move(lock, fileObject.getParent(), filter.getName(), "");
lock.releaseLock();
FileObject newFileObject = fileObject.getParent().getFileObject(filter.getName());
fileObject = newFileObject;
}
FileLock lock = fileObject.lock();
OutputStream os = fileObject.getOutputStream(lock);
Writer w = new OutputStreamWriter(os);
String s = filter.getCode();
w.write(s);
w.close();
lock.releaseLock();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
public void initFilters() {
FileSystem fs = Repository.getDefault().getDefaultFileSystem();
FileObject folder = fs.getRoot().getFileObject(FOLDER_ID);
FileObject[] children = folder.getChildren();
List<CustomFilter> customFilters = new ArrayList<CustomFilter>();
HashMap<CustomFilter, String> afterMap = new HashMap<CustomFilter, String>();
Set<CustomFilter> enabledSet = new HashSet<CustomFilter>();
HashMap<String, CustomFilter> map = new HashMap<String, CustomFilter>();
for (final FileObject fo : children) {
InputStream is = null;
String code = "";
FileLock lock = null;
try {
lock = fo.lock();
is = fo.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
String s;
StringBuffer sb = new StringBuffer();
while ((s = r.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
code = sb.toString();
} catch (FileNotFoundException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} finally {
try {
is.close();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
lock.releaseLock();
}
String displayName = fo.getName();
final CustomFilter cf = new CustomFilter(displayName, code);
map.put(displayName, cf);
String after = (String) fo.getAttribute(AFTER_ID);
afterMap.put(cf, after);
Boolean enabled = (Boolean) fo.getAttribute(ENABLED_ID);
if (enabled != null && (boolean) enabled) {
enabledSet.add(cf);
}
cf.getChangedEvent().addListener(new FilterChangedListener(fo, cf));
customFilters.add(cf);
}
for (int j = 0; j < customFilters.size(); j++) {
for (int i = 0; i < customFilters.size(); i++) {
List<CustomFilter> copiedList = new ArrayList<CustomFilter>(customFilters);
for (CustomFilter cf : copiedList) {
String after = afterMap.get(cf);
if (map.containsKey(after)) {
CustomFilter afterCf = map.get(after);
int index = customFilters.indexOf(afterCf);
int currentIndex = customFilters.indexOf(cf);
if (currentIndex < index) {
customFilters.remove(currentIndex);
customFilters.add(index, cf);
}
}
}
}
}
for (CustomFilter cf : customFilters) {
sequence.addFilter(cf);
if (enabledSet.contains(cf)) {
filterChain.addFilter(cf);
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
setLayout(new java.awt.BorderLayout());
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
/**
* Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
* To obtain the singleton instance, use {@link findInstance}.
*/
public static synchronized FilterTopComponent getDefault() {
if (instance == null) {
instance = new FilterTopComponent();
}
return instance;
}
/**
* Obtain the FilterTopComponent instance. Never call {@link #getDefault} directly!
*/
public static synchronized FilterTopComponent findInstance() {
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find Filter component. It will not be located properly in the window system.");
return getDefault();
}
if (win instanceof FilterTopComponent) {
return (FilterTopComponent) win;
}
ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior.");
return getDefault();
}
@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}
@Override
protected String preferredID() {
return PREFERRED_ID;
}
@Override
public ExplorerManager getExplorerManager() {
return manager;
}
@Override
public void componentOpened() {
Lookup.Template<FilterChain> tpl = new Lookup.Template<FilterChain>(FilterChain.class);
result = Utilities.actionsGlobalContext().lookup(tpl);
result.addLookupListener(this);
}
@Override
public void componentClosed() {
result.removeLookupListener(this);
result = null;
}
public void resultChanged(LookupEvent lookupEvent) {
setChain(Utilities.actionsGlobalContext().lookup(FilterChain.class));
/*
EditorTopComponent tc = EditorTopComponent.getActive();
if (tc != null) {
setChain(tc.getFilterChain());
}*/
}
public void setChain(FilterChain chain) {
updateComboBoxSelection();
}
private FileObject getFileObject(CustomFilter cf) {
FileObject fo = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(FOLDER_ID + "/" + cf.getName());
if (fo == null) {
try {
fo = org.openide.filesystems.Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(FOLDER_ID).createData(cf.getName());
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
return fo;
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
out.writeInt(filterSettings.size());
for (FilterSetting f : filterSettings) {
out.writeUTF(f.getName());
out.writeInt(f.getFilterCount());
for (Filter filter : f.getFilters()) {
CustomFilter cf = (CustomFilter) filter;
out.writeUTF(cf.getName());
}
}
CustomFilter prev = null;
for (Filter f : this.sequence.getFilters()) {
CustomFilter cf = (CustomFilter) f;
FileObject fo = getFileObject(cf);
if (getFilterChain().containsFilter(cf)) {
fo.setAttribute(ENABLED_ID, true);
} else {
fo.setAttribute(ENABLED_ID, false);
}
if (prev == null) {
fo.setAttribute(AFTER_ID, null);
} else {
fo.setAttribute(AFTER_ID, prev.getName());
}
prev = cf;
}
}
public CustomFilter findFilter(String name) {
for (Filter f : sequence.getFilters()) {
CustomFilter cf = (CustomFilter) f;
if (cf.getName().equals(name)) {
return cf;
}
}
return null;
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
int filterSettingsCount = in.readInt();
for (int i = 0; i < filterSettingsCount; i++) {
String name = in.readUTF();
FilterSetting s = new FilterSetting(name);
int filterCount = in.readInt();
for (int j = 0; j < filterCount; j++) {
String filterName = in.readUTF();
CustomFilter filter = findFilter(filterName);
if (filter != null) {
s.addFilter(filter);
}
}
filterSettings.add(s);
}
updateComboBox();
}
final static class ResolvableHelper implements Serializable {
private static final long serialVersionUID = 1L;
public Object readResolve() {
return FilterTopComponent.getDefault();
}
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
<settings version="1.0">
<module name="com.sun.hotspot.igv.filterwindow" spec="1.0"/>
<instanceof class="org.openide.windows.TopComponent"/>
<instanceof class="com.sun.hotspot.igv.filterwindow.FilterTopComponent"/>
<instance class="com.sun.hotspot.igv.filterwindow.FilterTopComponent" method="getDefault"/>
</settings>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tc-ref PUBLIC "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN" "http://www.netbeans.org/dtds/tc-ref2_0.dtd">
<tc-ref version="2.0" >
<module name="com.sun.hotspot.igv.filterwindow" spec="1.0"/>
<tc-id id="FilterTopComponent"/>
<state opened="true"/>
</tc-ref>

Some files were not shown because too many files have changed in this diff Show More