public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: Erik Groeneveld <erik@cq2.nl>
To: Andrew Haley <aph@redhat.com>
Cc: java@gcc.gnu.org
Subject: Re: GC leaks debugging
Date: Wed, 06 Apr 2011 14:30:00 -0000	[thread overview]
Message-ID: <BANLkTi=R2f4ryFMSwzQwkAkWm57yj5aE3Q@mail.gmail.com> (raw)
In-Reply-To: <4D9B112B.6000408@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2230 bytes --]

>> The tests work fine on OpenJDK.  What could cause GCJ to grow the heap
>> infinitely?
>
> I don't know because you won't show me the tests.

Yeah, of course, sorry.  I forgot to tell a few things.

This problem has been bothering me quite some time now, and I decided
to solve it once and forever.  I have written many different test, but
I am still not able to pinpoint a simple program to demonstrate the
results.  The problem occurred initially while using Lucene, but later
on also with Owlim.  Having written all kinds of test programs with
Lucene, from doing almost nothing to fully fletched indexing, I can
make no definite conclusions yet.

I am now circling around the problem, trying to enclose it from
different sides and I seek your help for giving me hints on what to
look for.  It is not lightly that I decided to bring it into this
mailing-list, knowing that it would claim many peoples time.

Now the test I am running is attached.  It indexes a very simple
document with a unique id each, first assuring is it deleted.  And
each loop, it reopens the index-reader and searcher.  This test starts
to get in trouble above 10,000,000 loops (documents).  The problem is
that when I remove code (I tested systematically), it only takes
longer for the heap to explode. The only test that ran properly was
when I only created Documents and not index them.  So perhaps it has
to do something with I/O.

I built the lucene dso with (full script attached):

gcj -shared -fPIC $JARFILE -o liblucene-core.so -Lgccinstall/lib -lgcj
-findirect-dispatch -fno-indirect-classes

and the test with (full scipt attached):

g++ -O0 -fPIC -g -o test test.cpp \
    -I../include/lucene \
    -L../gccinstall/lib64 \
    -lgcj \
    -L.. \
    -llucene-core \
    -findirect-dispatch \

GCC being the 4.6 branch from SVN, build with:

../gcc-4_6-branch/configure --prefix=$installdir --disable-multilib

I understand that this is a high-level approach, and you'll like a
smaller test that demonstrates the problem.  But I don't have that
yet.  Any suggestions you can come up with at this level are more than
welcome.

Meanwhile, I dive deeper into analysis of the heap.

Erik

[-- Attachment #2: test.cpp --]
[-- Type: text/x-c++src, Size: 4187 bytes --]


#include <gcj/cni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <iostream>

#include "java/lang/Throwable.h"
#include "java/lang/Integer.h"
#include "java/lang/Boolean.h"
#include "java/util/Collection.h"
#include "java/util/ArrayList.h"
#include "java/io/File.h"

#include "org/apache/lucene/index/Term.h"
#include "org/apache/lucene/index/IndexReader.h"
#include "org/apache/lucene/index/IndexReader$FieldOption.h"
#include "org/apache/lucene/index/IndexWriter.h"
#include "org/apache/lucene/index/IndexWriter$MaxFieldLength.h"
#include "org/apache/lucene/search/IndexSearcher.h"
#include "org/apache/lucene/document/Document.h" 
#include "org/apache/lucene/document/Field.h" 
#include "org/apache/lucene/document/Field$Index.h" 
#include "org/apache/lucene/document/Field$Store.h" 
#include "org/apache/lucene/document/Fieldable.h" 
#include "org/apache/lucene/analysis/standard/StandardAnalyzer.h" 
#include "org/apache/lucene/analysis/Analyzer.h" 
#include "org/apache/lucene/util/Version.h"
#include "org/apache/lucene/store/Directory.h"
#include "org/apache/lucene/store/LockFactory.h"
#include "org/apache/lucene/store/SimpleFSDirectory.h"
#include "org/apache/lucene/store/SimpleFSLockFactory.h"

using namespace org::apache::lucene;
using namespace org::apache::lucene::util;
using namespace org::apache::lucene::index;
using namespace org::apache::lucene::document;
using namespace org::apache::lucene::search;
using namespace org::apache::lucene::store;
using namespace java::lang;
using namespace java::util;

Directory* makeDirectory(String* path) {
    LockFactory* lockFactory = new SimpleFSLockFactory();
    return (Directory*) new SimpleFSDirectory(new java::io::File(path), lockFactory);
}

void _Jv_RunGC(void);
long _Jv_GCTotalMemory (void);

int main(int argc, char *argv[]) {
    JvCreateJavaVM(NULL);
    JvAttachCurrentThread(NULL, NULL);
    
    JvInitClass(&Integer::class$);
    JvInitClass(&IndexReader::class$);
    JvInitClass(&IndexWriter::class$);
    JvInitClass(&IndexWriter$MaxFieldLength::class$);
    JvInitClass(&IndexReader$FieldOption::class$);
    JvInitClass(&Field::class$);
    JvInitClass(&Field$Store::class$);
    JvInitClass(&Field$Index::class$);
    JvInitClass(&Version::class$);

    store::Directory* indexDirectory = makeDirectory(JvNewStringUTF("index2"));
    String* fieldName = JvNewStringUTF("field");
    String* term = JvNewStringUTF("term");
    String* idFieldName = JvNewStringUTF("id");

    index::IndexWriter* writer = NULL;
    try { 
        analysis::Analyzer* analyzer = new analysis::standard::StandardAnalyzer(util::Version::LUCENE_30);
        writer = new IndexWriter(indexDirectory, analyzer, true, IndexWriter$MaxFieldLength::UNLIMITED);
        writer->close();
        writer = new IndexWriter(indexDirectory, analyzer, true, IndexWriter$MaxFieldLength::UNLIMITED);
        IndexReader* reader = IndexReader::open(indexDirectory);
        IndexSearcher* searcher = new IndexSearcher(reader);
        while ( true ) {
            static int i = 0;
            if (i++ % 1000 == 0) {
                printf("%d %d\n", i, _Jv_GCTotalMemory());
                fflush(stdout);
            }
            Document* doc = new Document();
            Fieldable* field = (Fieldable*) new Field(fieldName, term, Field$Store::YES, Field$Index::ANALYZED);
            doc->add(field);
            String* id = Integer::toString(i);
            Fieldable* idField = (Fieldable*) new Field(idFieldName, id, Field$Store::YES, Field$Index::ANALYZED);
            doc->add(idField);
            Term* term = new Term(idFieldName, id);
            writer->deleteDocuments(term);
            writer->addDocument(doc);
            searcher->close();
            reader->close();
            reader = IndexReader::open(indexDirectory);
            Collection* fields = reader->getFieldNames(IndexReader$FieldOption::ALL);
            searcher = new IndexSearcher(reader);
        }
    }
    catch (Throwable* e) {
        e->printStackTrace();
        if (writer != NULL) {
            writer->close();
        }
        return 1;
    }
    writer->close();
    
    return 0;
}


[-- Attachment #3: buildlucenelib.sh --]
[-- Type: application/x-sh, Size: 2022 bytes --]

[-- Attachment #4: buildAndRun.sh --]
[-- Type: application/x-sh, Size: 350 bytes --]

  reply	other threads:[~2011-04-06 14:30 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01  8:39 Erik Groeneveld
2011-04-01  8:45 ` Andrew Haley
2011-04-01  9:03   ` Erik Groeneveld
2011-04-01  9:34     ` Andrew Haley
2011-04-02  0:27       ` Boehm, Hans
2011-04-02  9:39         ` Erik Groeneveld
2011-04-03 17:15           ` Erik Groeneveld
2011-04-03 18:00             ` Erik Groeneveld
2011-04-04  8:13               ` Andrew Haley
2011-04-04  8:53                 ` Erik Groeneveld
2011-04-04  9:48                   ` Andrew Haley
2011-04-05  4:44                     ` Boehm, Hans
2011-04-05  8:58                       ` Andrew Haley
2011-04-05  6:50                     ` Erik Groeneveld
2011-04-05  9:02                       ` Andrew Haley
2011-04-05 12:02                         ` Erik Groeneveld
2011-04-05 12:55                           ` Andrew Haley
2011-04-06 14:30                             ` Erik Groeneveld [this message]
2011-04-06 18:33                               ` Andrew Haley
2011-04-06 18:39                                 ` David Daney
2011-04-07 17:43                                 ` Erik Groeneveld
2011-04-08  8:12                                   ` Erik Groeneveld
2011-04-08 13:56                                   ` Andrew Haley
2011-04-08 15:35                                     ` David Daney
2011-04-08 15:53                                       ` Erik Groeneveld
2011-04-08 15:57                                         ` Andrew Haley
2011-04-08 15:48                                     ` Erik Groeneveld
2011-04-09  1:17                                     ` Boehm, Hans
2011-04-09  8:47                                       ` Andrew Haley
2011-04-09 10:56                                       ` Erik Groeneveld
2011-04-10 11:03                                         ` Erik Groeneveld
2011-04-12 18:43                                           ` Erik Groeneveld
2011-04-13  8:11                                             ` Andrew Haley
2011-04-13 12:11                                               ` Bryce McKinlay
2011-04-13 14:27                                                 ` Andrew Haley
2011-04-14  8:36                                               ` Erik Groeneveld
2011-04-14  8:43                                                 ` Andrew Haley
2011-04-14 10:02                                                   ` Erik Groeneveld
2011-04-14 10:50                                                     ` Andrew Haley
2011-04-15  7:32                                                       ` Erik J Groeneveld
2011-04-01 17:41 ` David Daney
2011-04-02 16:21   ` Erik Groeneveld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=R2f4ryFMSwzQwkAkWm57yj5aE3Q@mail.gmail.com' \
    --to=erik@cq2.nl \
    --cc=aph@redhat.com \
    --cc=java@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).