public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/16134] New: Memory leak in String.getBytes()
@ 2004-06-22 10:23 hannes at helma dot at
  2004-06-22 13:04 ` [Bug libgcj/16134] " hannes at helma dot at
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hannes at helma dot at @ 2004-06-22 10:23 UTC (permalink / raw)
  To: java-prs

Looks like there is a memory leak in java.lang.String.getBytes() in libgcj
3.3.3. The following code keeps growing continuously in memory:

//
// Test code for String.getBytes() memory leak
//     
    
public class StringBytesLeak {

    public static void main(String[] args) {
        while (true) {
            for (int i=0; i<10000; i++) {
                // leaks memory
                "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".getBytes();
                // using our own bogus implementation fixes the problem
                // getBytes("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException x) {
                System.exit(0);
            }
        }
    }

    // simplistic implementation of String.getBytes() that doesn't leak
    static byte[] getBytes(String str) {
        int length = str.length();
        byte[] bytes = new byte[length];
        for (int i=0; i<length; i++) 
            bytes[i] = (byte) str.charAt(i);
        return bytes;
    }

}

-- 
           Summary: Memory leak in String.getBytes()
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hannes at helma dot at
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org
 GCC build triplet: i686-suse-linux
  GCC host triplet: i686-suse-linux
GCC target triplet: i686-suse-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
@ 2004-06-22 13:04 ` hannes at helma dot at
  2004-06-22 13:54 ` hannes at helma dot at
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hannes at helma dot at @ 2004-06-22 13:04 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From hannes at helma dot at  2004-06-22 13:01 -------
OK, I found what's going on. 

The problem is in gnu.gcj.convert.UnicodeToBytesgetEncoder(String encoding)

SuSE 9.1 uses UTF-8 as standard, but the file.encoding System property is set to
"UTF-8" rather than the canonical "UTF8". Calling
UnicodeToBytesgetEncoder(String encoding) with a non-canonical encoding name
causes the lookup in the encoderCache to fail. A new Encoder instance is created
each time and the encoderCache is swamped with instances (at least that's what I
guess is happening).

The fix should be easy - just canonicalize() the encoding name before looking it
up in the cache (it is done afterwards anyway).

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
  2004-06-22 13:04 ` [Bug libgcj/16134] " hannes at helma dot at
@ 2004-06-22 13:54 ` hannes at helma dot at
  2004-06-22 16:51 ` mckinlay at redhat dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hannes at helma dot at @ 2004-06-22 13:54 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From hannes at helma dot at  2004-06-22 13:28 -------
That should have been UnicodeToBytes.getEncoder(String encoding) in the previous
comment (copy/paste error)

Looks like the same problem is present in BytesToUnicode.getDecoder(String
encoding).

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
  2004-06-22 13:04 ` [Bug libgcj/16134] " hannes at helma dot at
  2004-06-22 13:54 ` hannes at helma dot at
@ 2004-06-22 16:51 ` mckinlay at redhat dot com
  2004-06-22 17:21 ` mckinlay at redhat dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mckinlay at redhat dot com @ 2004-06-22 16:51 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-22 16:31:41
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
                   ` (2 preceding siblings ...)
  2004-06-22 16:51 ` mckinlay at redhat dot com
@ 2004-06-22 17:21 ` mckinlay at redhat dot com
  2004-06-22 17:23 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mckinlay at redhat dot com @ 2004-06-22 17:21 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From mckinlay at redhat dot com  2004-06-22 16:56 -------
There is certainly a problem with the encoder cache here in that cache lookups
will always fail. I've written the obvious patch and will check it in shortly.
However the leak you see is not due to this code directly because it never keeps
more than 4 encoder instances in the cache. Rather, it is due to the
stack-walking code leaking memory as part of the calling classloader check in
Class.forName(). This was fixed in gcc 3.4, see bug 12475.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
                   ` (3 preceding siblings ...)
  2004-06-22 17:21 ` mckinlay at redhat dot com
@ 2004-06-22 17:23 ` cvs-commit at gcc dot gnu dot org
  2004-06-22 18:22 ` mckinlay at redhat dot com
  2004-07-10  0:37 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-06-22 17:23 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-06-22 17:21 -------
Subject: Bug 16134

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bryce@gcc.gnu.org	2004-06-22 17:21:23

Modified files:
	libjava        : ChangeLog 
	libjava/gnu/gcj/convert: UnicodeToBytes.java BytesToUnicode.java 

Log message:
	PR libgcj/16134:
	* gnu/gcj/convert/BytesToUnicode.java: Canonicalize encoding name
	before cache lookup. Thanks to Hannes Wallnoefer.
	* gnu/gcj/convert/UnicodeToBytes.java: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.2875&r2=1.2876
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/gnu/gcj/convert/UnicodeToBytes.java.diff?cvsroot=gcc&r1=1.10&r2=1.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/gnu/gcj/convert/BytesToUnicode.java.diff?cvsroot=gcc&r1=1.9&r2=1.10



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
                   ` (4 preceding siblings ...)
  2004-06-22 17:23 ` cvs-commit at gcc dot gnu dot org
@ 2004-06-22 18:22 ` mckinlay at redhat dot com
  2004-07-10  0:37 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mckinlay at redhat dot com @ 2004-06-22 18:22 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From mckinlay at redhat dot com  2004-06-22 17:23 -------
Fix checked in.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libgcj/16134] Memory leak in String.getBytes()
  2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
                   ` (5 preceding siblings ...)
  2004-06-22 18:22 ` mckinlay at redhat dot com
@ 2004-07-10  0:37 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-10  0:37 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |3.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16134


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-07-10  0:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-22 10:23 [Bug libgcj/16134] New: Memory leak in String.getBytes() hannes at helma dot at
2004-06-22 13:04 ` [Bug libgcj/16134] " hannes at helma dot at
2004-06-22 13:54 ` hannes at helma dot at
2004-06-22 16:51 ` mckinlay at redhat dot com
2004-06-22 17:21 ` mckinlay at redhat dot com
2004-06-22 17:23 ` cvs-commit at gcc dot gnu dot org
2004-06-22 18:22 ` mckinlay at redhat dot com
2004-07-10  0:37 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).