Re: [cp-patches] FYI: Implemented an ObjectPool
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Ok, I have seen this class was removed now. So forget about this mail :) cu Robert Robert Schuster wrote: > Hi, > shouldn't the pooling class use a WeakHashMap? > > And then I want to admit that the Apidoc should really explain when to > use a pooled object and when it is not good to use it. Eg. for all kind > of MouseEvent I think it is not a good idea to use the pool because the > user can access the Point instance and store it somewhere. > > Putting such an object back in the pool (even if it was untouched in > Classpath API code) would sooner or later cause havoc (when the values > in the object are overwritten and the user did not expect that). > > And now an example to get to know whether I have understood how to use > the object pool correctly: > In JTable I would change all instantiations of Point to > ObjectPool.getPoint(). When new values for these internal objects are > available I set them with begin.x, begin.y and so on. > > When the JTable instance is freed (finalize) I return the Point > instances to the ObjectPool. > > Done right? > > cu > Robert > > Roman Kennke wrote: > >>>Hi, >>> >>> >>> >I implemented and added an ObjectPool class. Please measure! Don't assume that this will lead to better performance. I do follow your reasoning. But ultimately this is the job of the allocator/garbage collector. >>> >>> >>>I completely agree with you that ideally this should be done in the GC. >>>This is why I hestitate to actually introduce some 'optimizations'. I >>>don't know about the current situation in free VMs Garbage Collectors >>>and how the impact would be. It would be helpful if some VM hackers >>>could comment on the issue. >>> >>> >>> Please make it really easy to turn on/off caching so people can do real measurements of the performance impact. >>> >>> >>>I have added a flag in the ObjectPool that can turn off the cache. As >>>well as some counters that count how many objects are >>>requested/returned/created/pooled. This is not a very clever benchmark, >>>since it does not actually measure performance (time-wise). >>> >>> >>> And only introduce it when it is a clear win. >>> >>> >>>Seeing that it is quite difficult to find the right spots where objects >>>should actually be returned into the pool, I strongly hesitate now to >>>introduce anything. >>> >>> >>> What seems to happen a lot in larger projects is that someone introduces some pooling/caching of certain constructs and when some implementation detail somewhere else in the stack changes the pooling/caching isn't revised/remeasured to see if it still makes sense (or that it actually decreases performance given the new circumstances!). Don't let that happen in this case. >>> >>> >>>I won't. It would be nice if some folks would play a little and comment >>>on this issue. Note that the pool isn't actually in use in Classpath, it >>>only sits around now for testing. I committed the following changes that >>>could help benchmarking: >>> >>>2005-07-01 Roman Kennke <[EMAIL PROTECTED]> >>> >>>* gnu/classpath/ObjectPool.java: >>>Introduced flag for turning on/off caching. >>>(getInstance): Synchronized access to this method. >>>(borrowObject): Synchronized access to the pool. >>>Added some benchmarking statements. >>>(returnObject): Synchronized access to the pool. >>>Added some benchmarking statements. >>>(createObject): Synchronized access to the pool. >>>Added some benchmarking statements. >>>(printStats): New method. Prints out some stats about the pool >>> usage. >>> >>>/Roman >>> >>> >>> >>> >>> >>>Index: gnu/classpath/ObjectPool.java >>>=== >>>RCS file: /cvsroot/classpath/classpath/gnu/classpath/ObjectPool.java,v >>>retrieving revision 1.2 >>>diff -u -r1.2 ObjectPool.java >>>--- gnu/classpath/ObjectPool.java1 Jul 2005 10:58:07 - 1.2 >>>+++ gnu/classpath/ObjectPool.java1 Jul 2005 13:04:39 - >>>@@ -77,6 +77,12 @@ >>> public final class ObjectPool >>> { >>> >>>+ /** The maximum number of instances that we keep for each type. */ >>>+ private static final int MAX_POOL_SIZE = 128; >>>+ >>>+ /** This flag turns on/off caching (for benchmarking purposes). */ >>>+ private static final boolean IS_CACHING = true; >>>+ >>> /** The only instance of ObjectPool. */ >>> private static ObjectPool instance; >>> >>>@@ -87,6 +93,14 @@ >>>* requested type is in the pool. >>>*/ >>> private HashMap pool; >>>+ >>>+ /** >>>+ * Collect some stats in this fields. TODO: Can be removed later. >>>+ */ >>>+ int created = 0; >>>+ int requested = 0; >>>+ int returned = 0; >>>+ int pooled = 0; >>> >>> /** >>>* Creates a new instance of ObjectPool. This constructor is made pri
Re: [cp-patches] FYI: Implemented an ObjectPool
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, shouldn't the pooling class use a WeakHashMap? And then I want to admit that the Apidoc should really explain when to use a pooled object and when it is not good to use it. Eg. for all kind of MouseEvent I think it is not a good idea to use the pool because the user can access the Point instance and store it somewhere. Putting such an object back in the pool (even if it was untouched in Classpath API code) would sooner or later cause havoc (when the values in the object are overwritten and the user did not expect that). And now an example to get to know whether I have understood how to use the object pool correctly: In JTable I would change all instantiations of Point to ObjectPool.getPoint(). When new values for these internal objects are available I set them with begin.x, begin.y and so on. When the JTable instance is freed (finalize) I return the Point instances to the ObjectPool. Done right? cu Robert Roman Kennke wrote: > Hi, > > >>>I implemented and added an ObjectPool class. >> >>Please measure! Don't assume that this will lead to better performance. >>I do follow your reasoning. But ultimately this is the job of the >>allocator/garbage collector. > > > I completely agree with you that ideally this should be done in the GC. > This is why I hestitate to actually introduce some 'optimizations'. I > don't know about the current situation in free VMs Garbage Collectors > and how the impact would be. It would be helpful if some VM hackers > could comment on the issue. > > >>Please make it really easy to turn on/off caching so people can do real >>measurements of the performance impact. > > > I have added a flag in the ObjectPool that can turn off the cache. As > well as some counters that count how many objects are > requested/returned/created/pooled. This is not a very clever benchmark, > since it does not actually measure performance (time-wise). > > >> And only introduce it when it is >>a clear win. > > > Seeing that it is quite difficult to find the right spots where objects > should actually be returned into the pool, I strongly hesitate now to > introduce anything. > > >>What seems to happen a lot in larger projects is that someone introduces >>some pooling/caching of certain constructs and when some implementation >>detail somewhere else in the stack changes the pooling/caching isn't >>revised/remeasured to see if it still makes sense (or that it actually >>decreases performance given the new circumstances!). >>Don't let that happen in this case. > > > I won't. It would be nice if some folks would play a little and comment > on this issue. Note that the pool isn't actually in use in Classpath, it > only sits around now for testing. I committed the following changes that > could help benchmarking: > > 2005-07-01 Roman Kennke <[EMAIL PROTECTED]> > > * gnu/classpath/ObjectPool.java: > Introduced flag for turning on/off caching. > (getInstance): Synchronized access to this method. > (borrowObject): Synchronized access to the pool. > Added some benchmarking statements. > (returnObject): Synchronized access to the pool. > Added some benchmarking statements. > (createObject): Synchronized access to the pool. > Added some benchmarking statements. > (printStats): New method. Prints out some stats about the pool > usage. > > /Roman > > > > > > Index: gnu/classpath/ObjectPool.java > === > RCS file: /cvsroot/classpath/classpath/gnu/classpath/ObjectPool.java,v > retrieving revision 1.2 > diff -u -r1.2 ObjectPool.java > --- gnu/classpath/ObjectPool.java 1 Jul 2005 10:58:07 - 1.2 > +++ gnu/classpath/ObjectPool.java 1 Jul 2005 13:04:39 - > @@ -77,6 +77,12 @@ > public final class ObjectPool > { > > + /** The maximum number of instances that we keep for each type. */ > + private static final int MAX_POOL_SIZE = 128; > + > + /** This flag turns on/off caching (for benchmarking purposes). */ > + private static final boolean IS_CACHING = true; > + >/** The only instance of ObjectPool. */ >private static ObjectPool instance; > > @@ -87,6 +93,14 @@ > * requested type is in the pool. > */ >private HashMap pool; > + > + /** > + * Collect some stats in this fields. TODO: Can be removed later. > + */ > + int created = 0; > + int requested = 0; > + int returned = 0; > + int pooled = 0; > >/** > * Creates a new instance of ObjectPool. This constructor is made private > @@ -102,7 +116,7 @@ > * > * @return an ObjectPool instance ready for use > */ > - public static ObjectPool getInstance() > + public static synchronized ObjectPool getInstance() >{ > if (instance == null) >instance = new ObjectPool(); > @@ -123,15 +137,32 @@ >
[cp-patches] Re: Absolute URL parsing bug
Andrew Haley wrote: This URL is an absolute URL because its path begins with a "/": "jar:file:/usr/src/redhat/BUILD/jonas-4.3.3/jonas/output/JONAS_4_3_3/examples/webservices/beans/ws/temp/ejbjars/ws.jar!/META-INF/wsdl/ssbEndpoint.wsdl" [ An absolute file URL can look like: absoluteURI = "file" ":" abs_path abs_path = "/" path_segments That is, there is no need for "//". I don't see that in any of the specs. Technically, "file:/tmp/foo.html" is not a valid URI, as far as I can tell. I notice that firefox rewrites it (in the navigation bar) to "file:///tmp/foo.html". Now in practice we may want to allow "file:/tmp/foo.html", but it should be viewed as an unofficial short-hand for "file:///tmp/foo.html". And indeed, the URL spec in the SDK docs says 'If the spec's path component begins with a slash character "/" then the path is treated as absolute...' ] The *path* is absolute, but the URI isn't. This matters when resolving a relative URL against a base URI, such as he URL of the containing document. If we have a base URI "http://bar.com/baz/index.html"; and a reference "/tmp/foo.html" then the resolved URI is "http://bar.com/tmp/foo.html";. But we parse the spec looking for "//" to determine if a URL is absolute, A URL is absolute *only* if it has a "scheme". ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: API doc fixes for UndoableEditSupport and UndoManager
I committed this patch to fix some API doc links: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * javax/swing/undo/UndoManager.java: fixed API doc links, * javax/swing/undo/UndoableEditSupport.java: likewise. Regards, Dave Gilbert Index: javax/swing/undo/UndoManager.java === RCS file: /cvsroot/classpath/classpath/javax/swing/undo/UndoManager.java,v retrieving revision 1.4 diff -u -r1.4 UndoManager.java --- javax/swing/undo/UndoManager.java 16 Feb 2005 11:41:16 - 1.4 +++ javax/swing/undo/UndoManager.java 1 Jul 2005 20:52:44 - @@ -78,7 +78,7 @@ * javax.swing.undo package, the public methods of an * UndoManager are safe to call from concurrent threads. * The caller does not need to perform external synchronization, and - * [EMAIL PROTECTED] javax.swing.event.UndoableEvent} sources do not need to + * [EMAIL PROTECTED] javax.swing.event.UndoableEditEvent} sources do not need to * broadcast their events from inside the Swing worker thread. * * @author Sascha Brawer ([EMAIL PROTECTED]) @@ -607,7 +607,7 @@ * Thread Safety: This method may safely be invoked from * concurrent threads. The caller does not need to perform external * synchronization. This means that [EMAIL PROTECTED] - * javax.swing.event.UndoableEvent} sources do not need to broadcast + * javax.swing.event.UndoableEditEvent} sources do not need to broadcast * their events from inside the Swing worker thread. * * @param event the event whose edit will be Index: javax/swing/undo/UndoableEditSupport.java === RCS file: /cvsroot/classpath/classpath/javax/swing/undo/UndoableEditSupport.java,v retrieving revision 1.8 diff -u -r1.8 UndoableEditSupport.java --- javax/swing/undo/UndoableEditSupport.java 16 Feb 2005 11:41:16 - 1.8 +++ javax/swing/undo/UndoableEditSupport.java 1 Jul 2005 20:52:44 - @@ -187,7 +187,7 @@ /** - * If [EMAIL PROTECTED] #beginEdit} has been called (so that the current + * If [EMAIL PROTECTED] #beginUpdate} has been called (so that the current * update level is greater than zero), adds the specified edit * to [EMAIL PROTECTED] #compoundEdit}. Otherwise, notify listeners of the * edit by calling [EMAIL PROTECTED] #_postEdit(UndoableEdit)}. @@ -233,12 +233,12 @@ /** - * Creates a new instance of [EMAIL PROTECTED] #CompoundEdit}. Called by [EMAIL PROTECTED] + * Creates a new instance of [EMAIL PROTECTED] CompoundEdit}. Called by [EMAIL PROTECTED] * #beginUpdate}. If a subclass wants [EMAIL PROTECTED] #beginUpdate} to work * on a specific [EMAIL PROTECTED] #compoundEdit}, it should override this * method. * - * @returns a newly created instance of [EMAIL PROTECTED] #CompoundEdit}. + * @returns a newly created instance of [EMAIL PROTECTED] CompoundEdit}. */ protected CompoundEdit createCompoundEdit() { ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: RenderingHints API doc updates
I committed this patch to update some API docs: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * java/awt/RenderingHints.java: API doc updates. Regards, Dave Gilbert Index: java/awt/RenderingHints.java === RCS file: /cvsroot/classpath/classpath/java/awt/RenderingHints.java,v retrieving revision 1.5 diff -u -r1.5 RenderingHints.java --- java/awt/RenderingHints.java16 Feb 2005 10:39:26 - 1.5 +++ java/awt/RenderingHints.java1 Jul 2005 20:42:28 - @@ -1,5 +1,5 @@ /* RenderingHints.java -- - Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation + Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation This file is part of GNU Classpath. @@ -592,14 +592,18 @@ * Returns true if the collection of hints contains the * specified key, and false otherwise. * - * @param key the key. + * @param key the key (null not permitted). * * @return A boolean. + * + * @throws NullPointerException if key is null. + * @throws ClassCastException if key is not a [EMAIL PROTECTED] Key}. */ public boolean containsKey(Object key) { if (key == null) throw new NullPointerException(); +// don't remove the cast, it is necessary to throw the required exception return hintMap.containsKey((Key) key); } @@ -617,14 +621,20 @@ } /** - * Returns the value associated with the specified key. + * Returns the value associated with the specified key, or null + * if there is no value defined for the key. * - * @param key the key. + * @param key the key (null permitted). + * + * @return The value (possibly null). + * + * @throws ClassCastException if key is not a [EMAIL PROTECTED] Key}. * - * @return The value. + * @see #containsKey(Object) */ public Object get(Object key) { +// don't remove the cast, it is necessary to throw the required exception return hintMap.get((Key) key); } ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] Patch: RFA: fix gjdoc loop
This patch fixes a gjdoc bug we ran into while building Eclipse 3.1. I'm not checking it in yet as I am not a gjdoc expert; I'd rather someone else look it over first. Consider this code: package z; /** hi jane */ public class base extends der {} package z; import p.base; /** hi bob */ public class der extends base {} Note that there is no visible 'p.base'. If you run gjdoc on this, it will hang, because it thinks the 'base' in z/der.java refers to z/base.java -- which it does not. This patch fixes the problem by changing not-found single-type imports to return a result when match() is called. Tom Index: ChangeLog from Tom Tromey <[EMAIL PROTECTED]> * src/gnu/classpath/tools/gjdoc/RootDocImpl.java (ResolvedImportNotFound.name): New field. (ResolvedImportNotFound): Initialize it. (ResolvedImportNotFound.match): Implemented. Index: src/gnu/classpath/tools/gjdoc/RootDocImpl.java === RCS file: /cvsroot/classpath/gjdoc/src/gnu/classpath/tools/gjdoc/RootDocImpl.java,v retrieving revision 1.22 diff -u -r1.22 RootDocImpl.java --- src/gnu/classpath/tools/gjdoc/RootDocImpl.java 18 May 2005 11:52:30 - 1.22 +++ src/gnu/classpath/tools/gjdoc/RootDocImpl.java 1 Jul 2005 18:45:52 - @@ -664,10 +664,18 @@ implements ResolvedImport { private String importSpecifier; + private String name; ResolvedImportNotFound(String importSpecifier) { this.importSpecifier = importSpecifier; + int ndx = importSpecifier.lastIndexOf('.'); + if (ndx >= 0) { +this.name = importSpecifier.substring(ndx + 1); + } + else { +this.name = importSpecifier; + } } public String toString() @@ -677,7 +685,10 @@ public String match(String name) { - return null; // FIXME! +if (name.equals(this.name)) + return this.name; +// FIXME: note that we don't handle on-demand imports here. + return null; } public boolean mismatch(String name) ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] Patch: FYI: gjdoc import ordering fix
I'm checking this in. gjdoc processes imports in the wrong order. In particular it searches java.lang.* first, followed by the current package, and only then followed by any explicit imports. This patch fixes the bug by deferring the addition of the package and java.lang.* imports until after all the other import statements have been processed. Tom Index: ChangeLog from Tom Tromey <[EMAIL PROTECTED]> * src/gnu/classpath/tools/gjdoc/Parser.java (PackageComponent.process): Don't add to importedStatementList. (processSourceFile): Don't add java.lang.* to importedStatementList. (classOpened): Update importedStatementList here. Index: src/gnu/classpath/tools/gjdoc/Parser.java === RCS file: /cvsroot/classpath/gjdoc/src/gnu/classpath/tools/gjdoc/Parser.java,v retrieving revision 1.24 diff -u -r1.24 Parser.java --- src/gnu/classpath/tools/gjdoc/Parser.java 18 May 2005 11:52:31 - 1.24 +++ src/gnu/classpath/tools/gjdoc/Parser.java 1 Jul 2005 18:36:20 - @@ -1,5 +1,5 @@ /* gnu.classpath.tools.gjdoc.Parser - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -208,7 +208,6 @@ int process(Parser parser, char[] source, int startIndex, int endIndex) { String packageName=new String(source,startIndex+8,endIndex-startIndex-8-1).trim(); parser.packageOpened(packageName); - parser.importedStatementList.add(packageName + ".*"); return endIndex; } } @@ -733,7 +732,6 @@ importedStringList.clear(); importedPackagesList.clear(); importedStatementList.clear(); - importedStatementList.add("java.lang.*"); currentLine = 1; @@ -841,6 +839,10 @@ } } + if (currentPackageName != null) +importedStatementList.add(currentPackageName + ".*"); + importedStatementList.add("java.lang.*"); + ClassDocImpl classDoc = ClassDocImpl.createInstance((ctx!=null)?(ctx.classDoc):null, currentPackage, null, ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: Add 0.16 announcement
Hi, This adds the announcement to our homepage: 2005-07-01 Mark Wielaard <[EMAIL PROTECTED]> * doc/www.gnu.org/announce/20050630.wml: New file. * doc/www.gnu.org/newsitems.txt: Add announcement. * doc/www.gnu.org/downloads/downloads.wml: Add 0.16 download. Committed, Mark Index: doc/www.gnu.org/newsitems.txt === RCS file: /cvsroot/classpath/classpath/doc/www.gnu.org/newsitems.txt,v retrieving revision 1.28 diff -u -r1.28 newsitems.txt --- doc/www.gnu.org/newsitems.txt 1 May 2005 20:42:01 - 1.28 +++ doc/www.gnu.org/newsitems.txt 1 Jul 2005 17:06:25 - @@ -1,3 +1,8 @@ + + + + Index: doc/www.gnu.org/announce/20050630.wml === RCS file: doc/www.gnu.org/announce/20050630.wml diff -N doc/www.gnu.org/announce/20050630.wml --- /dev/null 1 Jan 1970 00:00:00 - +++ doc/www.gnu.org/announce/20050630.wml 1 Jul 2005 17:06:25 - @@ -0,0 +1,329 @@ +#!wml --include=.. + +#use wml::std::page +#use wml::std::lang +#use wml::fmt::isolatin +#use wml::std::case global=upper + + + + + +#include + + + +GNU Classpath 0.16 "Harmony!" released. + +We are pleased to announce a new developer snapshot of GNU Classpath. + +GNU Classpath, essential libraries for java, is a project to create free +core class libraries for use with runtimes, compilers and tools for the +java programming language. + +The GNU Classpath developer snapshot releases are not directly aimed +at the end user but are meant to be integrated into larger development +platforms. For example the GCC (gcj) and Kaffe projects will use the +developer snapshots as a base for future versions. + +This is the first release of GNU Classpath since our Harmony +collaboration with the Apache group. Instructions for developers +wanting to try out and help with the core library implementation can +be found at: http://developer.classpath.org/ + +New is our wiki with simple steps to setup a quick development +environment. For example developers using cygwin can find examples +here: http://developer.classpath.org/mediation/ClasspathOnCygwin + +Some highlights of changes in this release (more extensive list below): + +AWT GtkScrollBar and GtkImage improvements. All image operations are +now working correctly. Graphics2D has been upgraded to use Cairo +0.5.x. Free Swing updates for 1.5 top-level compatibility. JTree +interface completed. JFileChooser has been implemented. Completed +implementations of BoxLayout, GrayFilter and SplitPane. Upgraded the +Corba features to 1.3 and included new CORBA 2.3 features. Start of +generic JDWP framework. And lots of bug fixes based on real world +application usage. + +31 people actively contributed code to this release and made 389 CVS +commits during the last two months of development. diffstat since 0.15: +1248 files changed, 133649 insertions(+), 41802 deletions(-) + +More details about the various changes and contributions below. + +GNU Classpath 0.16 can be downloaded from +ftp://ftp.gnu.org/pub/gnu/classpath/ +or one of the ftp.gnu.org mirrors +http://www.gnu.org/order/ftp.html + +File: classpath-0.16.tar.gz +MD5sum: 220a9c86719a2c6bd7ba9b9877495113 +SHA1sum: be6d30fbfe4d71015a455a367411a6d55df3484e + +This release depends on gtk+ 2.4 for AWT support. But gtk+ 2.6 or +higher is recommended. Included, but not activated by default in this +release is a Graphics2D implementation based on the Cairo Graphics +framework (http://www.cairographics.org). Enabling this makes programs +like JEdit start up on GNU Classpath based runtimes. To enable this +support install the cairo 0.5.x snapshot, configure GNU Classpath with +--enable-gtk-cairo and make sure the system property +gnu.java.awt.peer.gtk.Graphics=Graphics2D is set. + +This release was explicitly tested against the last Eclipse 3.1 +release (thanks to various eclipse hackers for the support). For end +user we do however recommend to use the GCJ4 packaged version of +Eclipse 3.1 that have been prepared for the various distributions: + +Fedora Core + http://overholt.ca/wp/?p=27 +Debian GNU/Linux + http://gnu.wildebeest.org/diary-man-di/index.php?p=19 +Ubuntu + http://www.larvalstage.net/index.php?/archives/2-Introducing-Eclipse-3.1.html + +Not yet included is an implementation of Generic collection classes +and classes for other 1.5 language extensions. Work on this is being +done on a special development branch that will be included in a future +GNU Classpath release when free runtimes, compilers and tools have all +been upgraded to support these new language features. + +One of the major focuses of the GNU Classpath project is expanding +and using the Mauve test suite for Compatibility, Completeness and +Correctness checking. Various groups around GNU Classpath collaborate +on the free software Mauve test suite which contains ~30.000 core +library tests. Mauve has various modules for testing core class +library impl
[cp-patches] Proposed patch: JTable and DefaultTableColumnModel
This patch implements the isCellEditable() method in JTable and fixes a problem I noticed in DefaultTableColumnModel's moveColumn() method while I was writing the Mauve tests for the new method: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * javax/swing/JTable.java (convertColumnIndexToModel): remove check for > columnCount and let exception happen, (isCellEditable): implemented. * javax/swing/table/DefaultTableColumnModel.java (moveColumn): move the column, don't swap it. Also added argument checks. I've committed Mauve tests to back up these changes. OK to commit? Regards, Dave Index: javax/swing/JTable.java === RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v retrieving revision 1.28 diff -u -r1.28 JTable.java --- javax/swing/JTable.java 30 Jun 2005 20:35:00 - 1.28 +++ javax/swing/JTable.java 1 Jul 2005 16:52:33 - @@ -1027,8 +1027,6 @@ { if (vc < 0) return vc; -else if (vc > getColumnCount()) - return -1; else return columnModel.getColumn(vc).getModelIndex(); } @@ -2074,6 +2072,20 @@ dataModel.setValueAt(value, row, convertColumnIndexToModel(column)); } + /** + * Returns true if the specified cell is editable, and + * false otherwise. + * + * @param row the row index. + * @param column the column index. + * + * @return A boolean. + */ + public boolean isCellEditable(int row, int column) + { +return dataModel.isCellEditable(row, convertColumnIndexToModel(column)); + } + public TableColumn getColumn(Object identifier) { return columnModel.getColumn(columnModel.getColumnIndex(identifier)); Index: javax/swing/table/DefaultTableColumnModel.java === RCS file: /cvsroot/classpath/classpath/javax/swing/table/DefaultTableColumnModel.java,v retrieving revision 1.12 diff -u -r1.12 DefaultTableColumnModel.java --- javax/swing/table/DefaultTableColumnModel.java 7 Jan 2005 18:32:49 - 1.12 +++ javax/swing/table/DefaultTableColumnModel.java 1 Jul 2005 16:52:35 - @@ -147,10 +147,14 @@ */ public void moveColumn(int i, int j) { -Object tmp = tableColumns.get(i); -tableColumns.set(i, tableColumns.get(j)); -tableColumns.set(j, tmp); -fireColumnAdded(new TableColumnModelEvent(this,i,j)); +int columnCount = getColumnCount(); +if (i < 0 || i >= columnCount) + throw new IllegalArgumentException("Index 'i' out of range."); +if (j < 0 || j >= columnCount) + throw new IllegalArgumentException("Index 'j' out of range."); +Object column = tableColumns.remove(i); +tableColumns.add(j, column); +fireColumnAdded(new TableColumnModelEvent(this, i, j)); } /** ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: Removed ObjectPool
Hi, I did some simple benchmarks with the proposed ObjectPool thing. These show that there is really not much gain from it, at least in a real world environment (where the number of requested objects != number of returned objects). It can be somewhat expected that the speed performance actually decreases, but it is doing quite dramatically (factor of > 5). What I did not expect, that also memory usage is not significantly improved, actually getting worse (on JamVM), I think this is because of the not-ideal situation that I simulated, where not every object is beeing put back into the pool. Anyway, I consider this an interesting lesson (at least it was for me), and remove this class again from the tree, sorry for the noise. This does not mean that the object usage should not be improved in Swing and some Rectangles and Dimension be cached. There are several cases where a method like getBounds() (which allocates a new Rectangle) has a counterpart getBounds(Rectangle r) (which does not allocate a new Rectangle but uses r as return value). Also, we developers should be sensible with object allocations (or methods that possible allocate objects like getBounds()). In my benchmarks I got >3 Rectangles allocated within some seconds of the ODB starting up... 2005-07-01 Roman Kennke <[EMAIL PROTECTED]> * gnu/classpath/ObjectPool.java: Removed this class. Some simple benchmarks show that it brings not much gain and actually decreases performance speed-wise. no patch attached, source file has been removed. /Roman ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] Absolute URL parsing bug
This URL is an absolute URL because its path begins with a "/": "jar:file:/usr/src/redhat/BUILD/jonas-4.3.3/jonas/output/JONAS_4_3_3/examples/webservices/beans/ws/temp/ejbjars/ws.jar!/META-INF/wsdl/ssbEndpoint.wsdl" [ An absolute file URL can look like: absoluteURI = "file" ":" abs_path abs_path = "/" path_segments That is, there is no need for "//". And indeed, the URL spec in the SDK docs says 'If the spec's path component begins with a slash character "/" then the path is treated as absolute...' ] But we parse the spec looking for "//" to determine if a URL is absolute, and this is wrong. So, I suggest this patch. This bug was found because it breaks the JOnAS build. Andrew. 2005-07-01 Andrew Haley <[EMAIL PROTECTED]> * java/net/URL.java: Look only for "/" at the start of an absolute path, not "//". Index: java/net/URL.java === RCS file: /cvs/gcc/gcc/libjava/java/net/URL.java,v retrieving revision 1.51 diff -p -2 -u -r1.51 URL.java --- java/net/URL.java 27 Apr 2005 20:10:07 - 1.51 +++ java/net/URL.java 1 Jul 2005 16:39:22 - @@ -389,10 +389,11 @@ public final class URL implements Serial // If this is an absolute URL, then ignore context completely. -// An absolute URL must have chars prior to "://" but cannot have a colon -// right after the "://". The second colon is for an optional port value +// If this is an absolute URL, then ignore context completely. +// An absolute URL must have chars prior to ":/" but cannot have a colon +// right after "://". The second colon is for an optional port value // and implies that the host from the context is used if available. int colon; int slash = spec.indexOf('/'); -if ((colon = spec.indexOf("://", 1)) > 0 +if ((colon = spec.indexOf(":/", 1)) > 0 && ((colon < slash || slash < 0)) && ! spec.regionMatches(colon, "://:", 0, 4)) ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
Re: [cp-patches] Needs Approval: Patch - JList multiple selection including Shift-Click
> "Roman" == Roman Kennke <[EMAIL PROTECTED]> writes: Roman> - No need to make every field private. This could impact performance in Roman> some cases (like when inner classes access the private fields of Roman> enclosing classes, the compiler has to generate accessor methods for Roman> them). Ordinarily I enable the eclipse warning for this and then I make a given member package-private if it is actually used from an inner class. I also add a comment explaining this. Tom ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
Re: [cp-patches] [RFA/JDWP] Signature.java
On Wed, 2005-06-29 at 14:03 -0600, Tom Tromey wrote: > > "Aaron" == Aaron Luchko <[EMAIL PROTECTED]> writes: > > Aaron> This class adds support for reading and writing the string type in the > Aaron> JDWP spec http://java.sun.com/j2se/1.5.0/docs/guide/jpda/jdwp-spec.html > > Looks good, please check it in. Thanks, done Aaron ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] More XML fixes
This patch provides further corrections for cases where namespaced nodes are created in non-namespace-aware mode, improving interoperability with Xerces and other DOM implementations. There are also some fixes and feature enhancements for the XSLT processor. 2005-07-01 Chris Burdess <[EMAIL PROTECTED]> * gnu/xml/dom/DomNode.java, gnu/xml/dom/html2/DomHTMLCollection.java, gnu/xml/dom/html2/DomHTMLElement.java, gnu/xml/dom/html2/DomHTMLTableElement.java, gnu/xml/dom/html2/DomHTMLTableRowElement.java, gnu/xml/dom/html2/DomHTMLTableSectionElement.java, gnu/xml/transform/NodeNumberNode.java, gnu/xml/transform/Stylesheet.java, gnu/xml/transform/TemplateNode.java, gnu/xml/xpath/NameTest.java, gnu/xml/xpath/NamespaceTest.java: Corrections for cases where elements/attributes might have been created in non-namespace-aware mode. * gnu/xml/transform/StreamSerializer.java: Only apply HTML attribute reduction when attribute is defined as a boolean in the HTML DTD. * gnu/xml/transform/TransformerImpl.java: Add support for output indenting and cdata-section-elements output instruction. -- Chris Burdess Index: gnu/xml/dom/DomNode.java === RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/DomNode.java,v retrieving revision 1.5 diff -u -r1.5 DomNode.java --- gnu/xml/dom/DomNode.java26 Mar 2005 23:58:31 - 1.5 +++ gnu/xml/dom/DomNode.java1 Jul 2005 15:23:02 - @@ -1840,7 +1840,7 @@ if (ns1 != null && ns2 != null) { return ns1.equals(ns2) && - getLocalName().equals(other.getLocalName()); + equal(getLocalName(), other.getLocalName()); } // if neither has a namespace, this is a "no-namespace" name. Index: gnu/xml/dom/html2/DomHTMLCollection.java === RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLCollection.java,v retrieving revision 1.2 diff -u -r1.2 DomHTMLCollection.java --- gnu/xml/dom/html2/DomHTMLCollection.java12 Mar 2005 19:53:26 - 1.2 +++ gnu/xml/dom/html2/DomHTMLCollection.java1 Jul 2005 15:23:02 - @@ -99,7 +99,12 @@ { return NodeFilter.FILTER_SKIP; } -if (nodeNames != null && !acceptName(n.getLocalName())) +String localName = n.getLocalName(); +if (localName == null) + { +localName = n.getNodeName(); + } +if (nodeNames != null && !acceptName(localName)) { return NodeFilter.FILTER_SKIP; } @@ -152,6 +157,10 @@ { Node attr = attrs.item(i); String attrName = attr.getLocalName(); +if (attrName == null) + { +attrName = attr.getNodeName(); + } if (name.equalsIgnoreCase(attrName)) { return attr; Index: gnu/xml/dom/html2/DomHTMLElement.java === RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/html2/DomHTMLElement.java,v retrieving revision 1.3 diff -u -r1.3 DomHTMLElement.java --- gnu/xml/dom/html2/DomHTMLElement.java 14 Mar 2005 21:10:55 - 1.3 +++ gnu/xml/dom/html2/DomHTMLElement.java 1 Jul 2005 15:23:02 - @@ -76,6 +76,10 @@ { Node attr = attrs.item(i); String attrName = attr.getLocalName(); +if (attrName == null) + { +attrName = attr.getNodeName(); + } if (attrName.equalsIgnoreCase(name)) { return attr.getNodeValue(); @@ -121,6 +125,10 @@ { attr = attrs.item(i); String attrName = attr.getLocalName(); +if (attrName == null) + { +attrName = attr.getNodeName(); + } if (attrName.equalsIgnoreCase(name)) { if (value != null) @@ -162,7 +170,12 @@ for (Node parent = getParentNode(); parent != null; parent = parent.getParentNode()) { -if (name.equalsIgnoreCase(parent.getLocalName())) +String parentName = parent.getLocalName(); +if (parentName == null) + { + parentName = parent.getNodeName(); + } +if (name.equalsIgnoreCase(parentName)) { return parent; } @@ -178,7 +191,12 @@ for (Node child = getFirstChild(); child != null; child = child.getNextSibling()) { -if (name.equalsIgnoreCase(child.getLocalName())) +String childName = child.getLocalName(); +if (childName == null) + { +childName = child.getLocalName(); + } +if (name.equalsIgnoreCase(childName)) { return child; } Index: gnu/xml/dom/html2/DomHTMLTableElement.java === RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/h
Re: [cp-patches] FYI: Implemented an ObjectPool
Hi, > > I implemented and added an ObjectPool class. > > Please measure! Don't assume that this will lead to better performance. > I do follow your reasoning. But ultimately this is the job of the > allocator/garbage collector. I completely agree with you that ideally this should be done in the GC. This is why I hestitate to actually introduce some 'optimizations'. I don't know about the current situation in free VMs Garbage Collectors and how the impact would be. It would be helpful if some VM hackers could comment on the issue. > Please make it really easy to turn on/off caching so people can do real > measurements of the performance impact. I have added a flag in the ObjectPool that can turn off the cache. As well as some counters that count how many objects are requested/returned/created/pooled. This is not a very clever benchmark, since it does not actually measure performance (time-wise). > And only introduce it when it is > a clear win. Seeing that it is quite difficult to find the right spots where objects should actually be returned into the pool, I strongly hesitate now to introduce anything. > What seems to happen a lot in larger projects is that someone introduces > some pooling/caching of certain constructs and when some implementation > detail somewhere else in the stack changes the pooling/caching isn't > revised/remeasured to see if it still makes sense (or that it actually > decreases performance given the new circumstances!). > Don't let that happen in this case. I won't. It would be nice if some folks would play a little and comment on this issue. Note that the pool isn't actually in use in Classpath, it only sits around now for testing. I committed the following changes that could help benchmarking: 2005-07-01 Roman Kennke <[EMAIL PROTECTED]> * gnu/classpath/ObjectPool.java: Introduced flag for turning on/off caching. (getInstance): Synchronized access to this method. (borrowObject): Synchronized access to the pool. Added some benchmarking statements. (returnObject): Synchronized access to the pool. Added some benchmarking statements. (createObject): Synchronized access to the pool. Added some benchmarking statements. (printStats): New method. Prints out some stats about the pool usage. /Roman Index: gnu/classpath/ObjectPool.java === RCS file: /cvsroot/classpath/classpath/gnu/classpath/ObjectPool.java,v retrieving revision 1.2 diff -u -r1.2 ObjectPool.java --- gnu/classpath/ObjectPool.java 1 Jul 2005 10:58:07 - 1.2 +++ gnu/classpath/ObjectPool.java 1 Jul 2005 13:04:39 - @@ -77,6 +77,12 @@ public final class ObjectPool { + /** The maximum number of instances that we keep for each type. */ + private static final int MAX_POOL_SIZE = 128; + + /** This flag turns on/off caching (for benchmarking purposes). */ + private static final boolean IS_CACHING = true; + /** The only instance of ObjectPool. */ private static ObjectPool instance; @@ -87,6 +93,14 @@ * requested type is in the pool. */ private HashMap pool; + + /** + * Collect some stats in this fields. TODO: Can be removed later. + */ + int created = 0; + int requested = 0; + int returned = 0; + int pooled = 0; /** * Creates a new instance of ObjectPool. This constructor is made private @@ -102,7 +116,7 @@ * * @return an ObjectPool instance ready for use */ - public static ObjectPool getInstance() + public static synchronized ObjectPool getInstance() { if (instance == null) instance = new ObjectPool(); @@ -123,15 +137,32 @@ */ public Object borrowObject(Class type) { +// This is only here for benchmarking purposes. +if (!IS_CACHING) + return createObject(type); +// Counts the requested objects. This is only here for benchmarking +// purposes. +requested++; +if (requested % 1 == 0) + printStats(); + + Object object = null; -Stack pooledInstances = (Stack) pool.get(type); +Stack pooledInstances = null; +synchronized (this) + { + pooledInstances = (Stack) pool.get(type); + } if (pooledInstances == null) object = createObject(type); else if (pooledInstances.size() == 0) object = createObject(type); else - object = pooledInstances.pop(); + synchronized (this) + { + object = pooledInstances.pop(); + } return object; } @@ -142,14 +173,36 @@ */ public void returnObject(Object object) { +// This is only here for benchmarking purposes. +if (!IS_CACHING) + return; +// Count the returned objects. This is only here for benchmarking purposes. +returned++; + Class type = object.getClass(); -Stack pooledInstances = (Stack) pool.get(type); +Stack pooledInstances = null; +synchronized (this) + { + pooledInstances = (Stack) pool.get(
Re: [cp-patches] FYI: Implemented an ObjectPool: I think, the synchronization is necessary.
Roman Kennke wrote: I implemented and added an ObjectPool class. I suggest to synchronize (pool) { before doing anything with it }. Otherwise the parallel threads time to time grab the same object from the pool, causing the total chaos inside the application. Also, the pool may cause memory leak if the returnObject is called more often than borrowObject. Of course, this is only possible if some objects being returned were created outside the createObject, but the pool provides no any control on this. I suggest to control the balance of the borrowed/released objects or just put the size limit or use weak references. Despite one instance of the pool seems sufficient, I suggest to leave its constructor public. The application with many parallel threads may prefer to have an array of pools, every time selecting a random member to operate. This helps against the loss of performance due necessity for other threads to wait while one of them is getting/returning an object. The suggested pool will be highly effective on a machine with I think at least 4-8 processors. How on a single processor computer, I do not know. Cheers Audrius ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
Re: [cp-patches] FYI: Implemented an ObjectPool: I think, the synchronization is necessary.
Am Freitag, den 01.07.2005, 14:35 +0200 schrieb Meskauskas Audrius: > Roman Kennke wrote: > > >I implemented and added an ObjectPool class. > > > I suggest to synchronize (pool) { before doing anything with it }. Yeah, I added that. I will commit this ASAP. > Also, the pool may cause memory leak if the returnObject is called more > often than borrowObject. I also fixed this. Returned object are only added to the pool if the pool is not on its limit. ATM I have set the limit to 64 instances per type, this may or may not be good. Anyway, I am going to do some benchmarking first before 'optimizing' anything. > Despite one instance of the pool seems sufficient, I suggest to leave > its constructor public. The application with many parallel threads may > prefer to have an array of pools, every time selecting a random member > to operate. This helps against the loss of performance due necessity for > other threads to wait while one of them is getting/returning an object. That is right. I will consider this. Note that the pool is not open for use in applications anyway. /Roman ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
Re: [cp-patches] FYI: Implemented an ObjectPool
Hi Roman, On Fri, 2005-07-01 at 12:52 +0200, Roman Kennke wrote: > I implemented and added an ObjectPool class. This should help improve > performance in Swing (and other areas). In Swing we make heavy use of > Point Dimension and Rectangle. Usually these objects are created to wrap > some integer values and are discarded quickly. This would create > overload for creating and garbage collecting these instances which is > not necessary if these objects are cached. Please measure! Don't assume that this will lead to better performance. I do follow your reasoning. But ultimately this is the job of the allocator/garbage collector. This cache is kind of a hint that the objects created are small and short lived. And that is nice. But if the garbage collector already noticed that anyway we are doing double work. Please make it really easy to turn on/off caching so people can do real measurements of the performance impact. And only introduce it when it is a clear win. Since as you said it has some drawback because you have to manually track usage patterns now. What seems to happen a lot in larger projects is that someone introduces some pooling/caching of certain constructs and when some implementation detail somewhere else in the stack changes the pooling/caching isn't revised/remeasured to see if it still makes sense (or that it actually decreases performance given the new circumstances!). Don't let that happen in this case. Cheers, Mark signature.asc Description: This is a digitally signed message part ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: small API doc fix for javax.swing.plaf.ListUI
I committed this patch to correct a minor problem in the API docs: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * javax/swing/plaf/ListUI.java (locationToIndex): match parameter name to API docs. Regards, Dave Gilbert Index: javax/swing/plaf/ListUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/ListUI.java,v retrieving revision 1.5 diff -u -r1.5 ListUI.java --- javax/swing/plaf/ListUI.java22 Oct 2004 12:44:00 - 1.5 +++ javax/swing/plaf/ListUI.java1 Jul 2005 11:05:38 - @@ -1,5 +1,5 @@ /* ListUI.java -- - Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -75,7 +75,7 @@ * @return the index of the closest cell, or -1 if the list model * is empty. */ - public abstract int locationToIndex(JList index, Point location); + public abstract int locationToIndex(JList list, Point location); /** ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] Re: [commit-cp] classpath ./ChangeLog gnu/xml/dom/DomDocument.j...
Hi Chris, On Thu, 2005-06-30 at 18:09 -0400, Chris Burdess wrote: > CVSROOT: /cvsroot/classpath > Module name: classpath > Branch: > Changes by: Chris Burdess <[EMAIL PROTECTED]> 05/06/30 22:09:07 Reading the main mailinglist I see this wasn't a mistaken commit. But I didn't see a post about this on classpath-patches. Could you please always post your patches there so people know what changed without having to follow the automatic commit mailinglist. It is just one extra step that I feel we must do to make peer review easier and more robust (even if everybody trusts your judgment on XML matters of course!) Thanks, Mark signature.asc Description: This is a digitally signed message part ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: API doc updates in javax.swing.table package
I committed the following patch to make some small updates to the API docs for javax.swing.table: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * javax/swing/table/JTableHeader.java: added some API docs, * javax/swing/table/TableModel.java: fixed link in API docs, * javax/swing/table/package.html: added package description. Regards, Dave Gilbert ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: fixed small error in ObjectPool
Of course the singleton instance and its accessor method must be static, otherwise this class is not of much use. 2005-07-01 Roman Kennke <[EMAIL PROTECTED]> * gnu/classpath/ObjectPool.java: Made singleton instance static. Otherwise this class would not be of much use. (getInstance): Made this method static. /Roman Index: gnu/classpath/ObjectPool.java === RCS file: /cvsroot/classpath/classpath/gnu/classpath/ObjectPool.java,v retrieving revision 1.1 diff -u -r1.1 ObjectPool.java --- gnu/classpath/ObjectPool.java 1 Jul 2005 10:46:14 - 1.1 +++ gnu/classpath/ObjectPool.java 1 Jul 2005 10:57:33 - @@ -78,7 +78,7 @@ { /** The only instance of ObjectPool. */ - private ObjectPool instance; + private static ObjectPool instance; /** * The object pool. This maps Class objects (the type of the pooled objects) @@ -102,7 +102,7 @@ * * @return an ObjectPool instance ready for use */ - public ObjectPool getInstance() + public static ObjectPool getInstance() { if (instance == null) instance = new ObjectPool(); ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: Implemented an ObjectPool
I implemented and added an ObjectPool class. This should help improve performance in Swing (and other areas). In Swing we make heavy use of Point Dimension and Rectangle. Usually these objects are created to wrap some integer values and are discarded quickly. This would create overload for creating and garbage collecting these instances which is not necessary if these objects are cached. Instead of caching such objects in private instance fields, I think it would be much better to use an object pool like this. Please keep in mind that you must take care when you use the ObjectPool. While it is useful it also has one drawback: you have to explicitly release the object back to the pool (in the current implementation). So you should be fairly certain that the pooled object is not stored in a different location. Also, you have to manually take care of the actual state of the pooled object. Of course, the ObjectPool is not limited to be used in Swing. On how to use the pool, please review the API docs of that class. 2005-07-01 Roman Kennke <[EMAIL PROTECTED]> * gnu/classpath/ObjectPool.java: New class. This can and should be used to cache throwaway objects like Rectangles, Points and Dimensions. Of course the use of this class is not limited to this cases. /Roman Index: gnu/classpath/ObjectPool.java === RCS file: gnu/classpath/ObjectPool.java diff -N gnu/classpath/ObjectPool.java --- /dev/null 1 Jan 1970 00:00:00 - +++ gnu/classpath/ObjectPool.java 1 Jul 2005 10:44:14 - @@ -0,0 +1,180 @@ +/* ObjectPool.java -- A generic object pool. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.classpath; + +import java.util.HashMap; +import java.util.Stack; + +/** + * A generic object pool that can be used to cache frequently used + * objects. Typical examples are 'throwaway' objects like java.awt.Dimension + * java.awt.Rectangle and java.awt.Point of which are created plenty in + * Swing but that usually have a very short lifecycle. For such objects + * it is much more efficient to hold them in an object pool, because the + * overhead of allocating heap and garbage collecting is avoided. + * + * To use this pool you have to do 3 steps: + * + * Get a reference to the (singleton) ObjectPool instance. + * Get a reference to an object of the correct type; Do something with it + * + * After use, return the object back to the pool. + * + * Note that you should never make any assumptions about the state of such + * an object, you are responsible to take care of this before you use the + * object. + * + * If a requested object is not available in the pool, then a new instance + * is created. It is therefore only possible to pool objects that have + * a zero-argument default constructor. + * + * Example (using a java.awt.Point object): + * + * ObjectPool pool = ObjectPool.getInstance(); + * Point point = (Point) pool.borrowObject(Point.class); + * doSomething(point); + * pool.returnObject(point); + * + * + * + * @author Roman Kennke ([EMAIL PROTECTED]) + */ +public final class ObjectPool +{ + + /** The only instance of ObjectPool. */ + private ObjectPool instance; + + /** + * The object pool. This maps Class objects (the type of the
[cp-patches] FYI: API doc updates for java.awt.image.DataBufferXXX classes
I committed this patch to update the API doc descriptions for the DataBuffer classes. I also removed a few unnecessary casts that Eclipse highlighted. 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * java/awt/image/DataBuffer.java: fixed API doc typos; * java/awt/image/DataBufferByte.java: added description to API docs; * java/awt/image/DataBufferDouble.java: added description to API docs, (setElem(int, int)): removed unnecessary cast; (setElem(int, int, int)): likewise. * java/awt/image/DataBufferFloat.java: added description to API docs; (setElem(int, int)): removed unnecessary cast; (setElem(int, int, int)): likewise. * java/awt/image/DataBufferInt.java: added description to API docs; * java/awt/image/DataBufferShort.java: likewise; * java/awt/image/DataBufferUShort.java: likewise. Regards, Dave Gilbert Index: java/awt/image/DataBuffer.java === RCS file: /cvsroot/classpath/classpath/java/awt/image/DataBuffer.java,v retrieving revision 1.4 diff -u -r1.4 DataBuffer.java --- java/awt/image/DataBuffer.java 16 Feb 2005 10:39:27 - 1.4 +++ java/awt/image/DataBuffer.java 1 Jul 2005 10:22:22 - @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation +/* Copyright (C) 2000, 2002, 2005 Free Software Foundation This file is part of GNU Classpath. @@ -46,43 +46,43 @@ public abstract class DataBuffer { /** - * A constant representng a data type that uses byte primitives + * A constant representing a data type that uses byte primitives * as the storage unit. */ public static final int TYPE_BYTE = 0; /** - * A constant representng a data type that uses short + * A constant representing a data type that uses short * primitives as the storage unit. */ public static final int TYPE_USHORT= 1; /** - * A constant representng a data type that uses short + * A constant representing a data type that uses short * primitives as the storage unit. */ public static final int TYPE_SHORT = 2; /** - * A constant representng a data type that uses int + * A constant representing a data type that uses int * primitives as the storage unit. */ public static final int TYPE_INT = 3; /** - * A constant representng a data type that uses float + * A constant representing a data type that uses float * primitives as the storage unit. */ public static final int TYPE_FLOAT = 4; /** - * A constant representng a data type that uses double + * A constant representing a data type that uses double * primitives as the storage unit. */ public static final int TYPE_DOUBLE= 5; /** - * A constant representng an undefined data type. + * A constant representing an undefined data type. */ public static final int TYPE_UNDEFINED = 32; Index: java/awt/image/DataBufferByte.java === RCS file: /cvsroot/classpath/classpath/java/awt/image/DataBufferByte.java,v retrieving revision 1.6 diff -u -r1.6 DataBufferByte.java --- java/awt/image/DataBufferByte.java 16 Feb 2005 10:39:27 - 1.6 +++ java/awt/image/DataBufferByte.java 1 Jul 2005 10:22:22 - @@ -47,6 +47,9 @@ code is a maintenance nightmare. */ /** + * A [EMAIL PROTECTED] DataBuffer} that uses an array of byte primitives + * to represent each of its banks. + * * @author Rolf W. Rasmussen ([EMAIL PROTECTED]) */ public final class DataBufferByte extends DataBuffer Index: java/awt/image/DataBufferDouble.java === RCS file: /cvsroot/classpath/classpath/java/awt/image/DataBufferDouble.java,v retrieving revision 1.4 diff -u -r1.4 DataBufferDouble.java --- java/awt/image/DataBufferDouble.java16 Feb 2005 10:39:27 - 1.4 +++ java/awt/image/DataBufferDouble.java1 Jul 2005 10:22:22 - @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 Free Software Foundation +/* Copyright (C) 2004, 2005 Free Software Foundation This file is part of GNU Classpath. @@ -47,6 +47,9 @@ code is a maintenance nightmare. */ /** + * A [EMAIL PROTECTED] DataBuffer} that uses an array of double primitives + * to represent each of its banks. + * * @since 1.4 * * @author Rolf W. Rasmussen ([EMAIL PROTECTED]) @@ -226,7 +229,7 @@ */ public void setElem(int i, int val) { -data[i+offset] = (double) val; +data[i+offset] = val; } /** @@ -240,7 +243,7 @@ */ public void setElem(int bank, int i, int val) { -bankData[bank][i+offsets[bank]] = (double) val; +bankData[bank][i+offsets[bank]] = val; } public float getElemFloat(int i) Index: java/awt/image/DataBufferFloat.java === RCS file
[cp-patches] FYI: JLayeredPane fix
The attached patch fixes JLayeredPane.getLayer(). It now searches through the components parents first to find the component that is actually contained in the JLayeredPane. Otherwise we would get IllegalArgumentExceptions for all components that are only indirectly contained in a JLayeredPane. 2005-07-01 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/JLayeredPane.java (getLayer): Also search through the components parents to find the one that is actually directly contained in the JLayeredPane. /Roman Index: javax/swing/JLayeredPane.java === RCS file: /cvsroot/classpath/classpath/javax/swing/JLayeredPane.java,v retrieving revision 1.21 diff -u -r1.21 JLayeredPane.java --- javax/swing/JLayeredPane.java 30 May 2005 12:16:17 - 1.21 +++ javax/swing/JLayeredPane.java 1 Jul 2005 10:31:13 - @@ -124,9 +124,18 @@ */ public int getLayer(Component c) { -if (! componentToLayer.containsKey (c)) - throw new IllegalArgumentException (); -return ((Integer) componentToLayer.get(c)).intValue(); +Component myComp = c; +while(! componentToLayer.containsKey(myComp)) + { + myComp = myComp.getParent(); + if (myComp == null) + break; + } +if (myComp == null) + throw new IllegalArgumentException + ("component is not in this JLayeredPane"); +Integer layerObj = (Integer) componentToLayer.get(myComp); +return layerObj.intValue(); } /** ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: Made some components opaque
I noticed that several components that should be opaque (they are in the JDK), are not flagged as beeing opaque in Classpath. I fixed this with the attached patch. At the moment this only affects the drawing in that the opaque flag decides if the ComponentUI draws the components background or not. I am working on an improved RepaintManager that also uses the opaque flag to optimize drawing. It would not be necessary to step back up to the RootPane and draw everything if the opaque property is correctly respected. 2005-06-30 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicMenuBarUI.java (installDefaults): Made JMenuBar opaque. * javax/swing/plaf/basic/BasicOptionPaneUI.java (installDefaults): Made JOptionPane opaque. * javax/swing/plaf/basic/BasicPanelUI.java (installUI): Also call installDefaults(). (installDefaults): New method. Made JPanel opaque. * javax/swing/plaf/basic/BasicRootPaneUI.java (installDefaults): Made JRootPane opaque. * javax/swing/plaf/basic/BasicSeparatorUI.java (installDefaults): Made JSeparator opaque. * javax/swing/plaf/basic/BasicSpinnerUI.java (installDefaults): Made JSpinner opaque. * javax/swing/plaf/basic/BasicSplitPaneUI.java (installDefaults): Made JSplitPane opaque. * javax/swing/plaf/basic/BasicTabbedPaneUI.java (installDefaults): Made JSplitPane opaque. /Roman Index: javax/swing/plaf/basic/BasicMenuBarUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicMenuBarUI.java,v retrieving revision 1.7 diff -u -r1.7 BasicMenuBarUI.java --- javax/swing/plaf/basic/BasicMenuBarUI.java 12 Apr 2005 19:48:44 - 1.7 +++ javax/swing/plaf/basic/BasicMenuBarUI.java 1 Jul 2005 10:10:19 - @@ -165,6 +165,7 @@ menuBar.setBorder(defaults.getBorder("MenuBar.border")); menuBar.setFont(defaults.getFont("MenuBar.font")); menuBar.setForeground(defaults.getColor("MenuBar.foreground")); +menuBar.setOpaque(true); } /** Index: javax/swing/plaf/basic/BasicOptionPaneUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicOptionPaneUI.java,v retrieving revision 1.17 diff -u -r1.17 BasicOptionPaneUI.java --- javax/swing/plaf/basic/BasicOptionPaneUI.java 4 Jun 2005 19:16:11 - 1.17 +++ javax/swing/plaf/basic/BasicOptionPaneUI.java 1 Jul 2005 10:10:20 - @@ -1146,6 +1146,7 @@ optionPane.setBackground(defaults.getColor("OptionPane.background")); optionPane.setForeground(defaults.getColor("OptionPane.foreground")); optionPane.setBorder(defaults.getBorder("OptionPane.border")); +optionPane.setOpaque(true); messageBorder = defaults.getBorder("OptionPane.messageAreaBorder"); messageForeground = defaults.getColor("OptionPane.messageForeground"); Index: javax/swing/plaf/basic/BasicPanelUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicPanelUI.java,v retrieving revision 1.4 diff -u -r1.4 BasicPanelUI.java --- javax/swing/plaf/basic/BasicPanelUI.java 14 Feb 2004 21:42:56 - 1.4 +++ javax/swing/plaf/basic/BasicPanelUI.java 1 Jul 2005 10:10:20 - @@ -39,18 +39,29 @@ package javax.swing.plaf.basic; import javax.swing.JComponent; +import javax.swing.JPanel; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.PanelUI; public class BasicPanelUI extends PanelUI { -public static ComponentUI createUI(JComponent x) -{ -return new BasicPanelUI(); -} + public static ComponentUI createUI(JComponent x) + { +return new BasicPanelUI(); + } -public void installUI(JComponent c) -{ - super.installUI(c); -} + public void installUI(JComponent c) + { +super.installUI(c); +if (c instanceof JPanel) + { + JPanel p = (JPanel) c; + installDefaults(p); + } + } + + public void installDefaults(JPanel p) + { +p.setOpaque(true); + } } Index: javax/swing/plaf/basic/BasicRootPaneUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicRootPaneUI.java,v retrieving revision 1.6 diff -u -r1.6 BasicRootPaneUI.java --- javax/swing/plaf/basic/BasicRootPaneUI.java 22 Oct 2004 12:44:01 - 1.6 +++ javax/swing/plaf/basic/BasicRootPaneUI.java 1 Jul 2005 10:10:20 - @@ -56,7 +56,6 @@ public void installUI(JComponent c) { -c.setOpaque(true); c.setBackground(UIManager.getColor("control")); super.installUI(c); } Index: javax/swing/plaf/basic/BasicSeparatorUI.java === RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSeparatorUI.java,v retrieving revision 1.4 diff -u -r1.4 BasicSeparator
[cp-patches] FYI: two minor fixes for MetalLookAndFeel/MetalTheme
I committed this patch to correct a couple of minor errors: (1) MetalLookAndFeel.isNativeLookAndFeel() should return false; (2) MetalTheme.getMenuDisabledForeground() was returning the wrong shade. Changelog entry: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * javax/swing/plaf/metal/MetalLookAndFeel.java (isNativeLookAndFeel): fixed return value, * javax/swing/plaf/metal/MetalTheme.java (getMenuDisabledForeground): fixed return value. I've also added corresponding tests to Mauve. Regards, Dave Gilbert ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
[cp-patches] FYI: small fix for TableModelEvent constructor
I committed this small patch to fix a couple of Mauve tests: 2005-07-01 David Gilbert <[EMAIL PROTECTED]> * javax/swing/event/TableModelEvent.java: (TableModelEvent(TableModel): set lastRowIndex to Integer.MAX_VALUE. Regards, Dave Gilbert Index: javax/swing/event/TableModelEvent.java === RCS file: /cvsroot/classpath/classpath/javax/swing/event/TableModelEvent.java,v retrieving revision 1.8 diff -u -r1.8 TableModelEvent.java --- javax/swing/event/TableModelEvent.java 29 Jun 2005 10:06:51 - 1.8 +++ javax/swing/event/TableModelEvent.java 1 Jul 2005 08:41:25 - @@ -99,7 +99,7 @@ */ public TableModelEvent(TableModel source) { -this(source, 0, source.getRowCount(), ALL_COLUMNS, UPDATE); +this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE); } /** ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches
Re: [cp-patches] FYI: JTable changeSelection and multiple selection implementation
Hi, > I have a small performance suggestion for the class in this patch. > > > @@ -131,7 +141,7 @@ > > public void mouseDragged(MouseEvent e) > > { > >curr = new Point(e.getX(), e.getY()); > > - updateSelection(); > > + updateSelection(e.isControlDown()); > > } > > public void mouseEntered(MouseEvent e) > > { > > @@ -146,7 +156,8 @@ > > { > >begin = new Point(e.getX(), e.getY()); > >curr = new Point(e.getX(), e.getY()); > > - updateSelection(); > > + updateSelection(e.isControlDown()); > > + > The Point instantiations will IMHO happen very often. I would change the > code in a way that 'curr' and 'begin' are just updated with the new > values of 'e' instead of creating a new instance every time. Yeah, this is becoming a real problem in Swing. The same holds true for Rectangle and Dimension instances. More of them should be cached and reused. Maybe we should add a little pool implementation, so we avoid having Point/Rectangle/Dimension cache fields all over the Swing classes.? Instead of writing 'new Point(x, y)' this would change to 'Pool.getPoint(x, y)' or something like this. Any comments? /Roman ___ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches