SWIG java代码& valgrind报告内存泄漏

时间:2013-08-06 07:20:59

标签: java c++ java-native-interface valgrind swig

我通过SWIG向C ++公开了一个C ++类。我有valgrind在valgrind中分别描述了C ++类,它没有显示内存泄漏问题。但是当运行由valgrind下的swig生成的JNI java类时,它会报告一些内存泄漏。

这是我调用valgrind的方式

  

LD_LIBRARY_PATH = / lib64下/ :. valgrind --trace-children = yes --smc-check = all --leak-check = full --show-reachable = yes java -Djava.compiler = NONE -Djava.library.path =。:/ lib64 / -classpath yCRF.jar :. testYCRF

Valgrind错误如下


==30758== 147,456 bytes in 18 blocks are still reachable in loss record 729 of 731
==30758==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==30758==    by 0x59927F6: os::malloc(unsigned long) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5489FCE: AllocateHeap(unsigned long, char const*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x57387A4: Hashtable::new_entry(unsigned int, Symbol*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A7D782: SymbolTable::basic_add(constantPoolHandle, int, char const**, int*, int*, unsigned int*, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A7DBAF: SymbolTable::add(constantPoolHandle, int, char const**, int*, int*, unsigned int*, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x55CE041: ClassFileParser::parse_constant_pool_entries(constantPoolHandle, int, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x55D26CF: ClassFileParser::parse_constant_pool(Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x55D4D2D: ClassFileParser::parseClassFile(Symbol*, Handle, Handle, KlassHandle, GrowableArray*, TempNewSymbol&, bool, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x55D9234: ClassLoader::load_classfile(Symbol*, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A87196: SystemDictionary::load_instance_class(Symbol*, Handle, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A87980: SystemDictionary::resolve_instance_class_or_null(Symbol*, Handle, Handle, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758== 
==30758== 160,088 bytes in 1 blocks are still reachable in loss record 730 of 731
==30758==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==30758==    by 0x59927F6: os::malloc(unsigned long) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5AD4016: universe_init() (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5757D24: init_globals() (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5ABB051: Threads::create_vm(JavaVMInitArgs*, bool*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x57B7C33: JNI_CreateJavaVM (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x4C3DF8D: JavaMain (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/jli/libjli.so)
==30758==    by 0x311F607850: start_thread (pthread_create.c:301)
==30758==    by 0x607A6FF: ???
==30758== 
==30758== 456,768 bytes in 1 blocks are still reachable in loss record 731 of 731
==30758==    at 0x4A0577B: calloc (vg_replace_malloc.c:593)
==30758==    by 0x66F3AC5: readCEN (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/libzip.so)
==30758==    by 0x66F4295: ZIP_Put_In_Cache0 (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/libzip.so)
==30758==    by 0x55DA3F8: ClassLoader::create_class_path_entry(char*, stat, ClassPathEntry**, bool) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x55DB1BE: LazyClassPathEntry::open_stream(char const*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x55D91B8: ClassLoader::load_classfile(Symbol*, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A87196: SystemDictionary::load_instance_class(Symbol*, Handle, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A87980: SystemDictionary::resolve_instance_class_or_null(Symbol*, Handle, Handle, Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5A8869E: SystemDictionary::initialize_preloaded_classes(Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5AD4603: Universe::genesis(Thread*) (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5AD4AB3: universe2_init() (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758==    by 0x5757D7C: init_globals() (in /home/y/libexec64/jdk1.7.0/jre/lib/amd64/server/libjvm.so)
==30758== 
==30758== LEAK SUMMARY:
==30758==    definitely lost: 3,952 bytes in 31 blocks
==30758==    indirectly lost: 4,832 bytes in 13 blocks
==30758==      possibly lost: 163,507 bytes in 399 blocks
==30758==    still reachable: 1,491,202 bytes in 9,354 blocks
==30758==         suppressed: 0 bytes in 0 blocks

可以在https://www.dropbox.com/s/ybx7e2nv5z0gqzi/valgrind.txt

访问完整的valgrind输出

我试图了解这些泄漏的性质。它们似乎没有指向我的代码。这些真的是我应该担心的错误,还是由于JNI的一些怪癖,valgrind表现得很疯狂?

修改 我尝试了一个没有任何JNI组件的简单java代码。

//import com.ycrf.Translit;

import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;

public class testYCRF {

public static void main(String[] argv) throws InterruptedException {
    List<String> words =
        Arrays.asList("hum", "jithine", "baap", "chasen"
                //"beti", "beta", "pragya", "hamara",
                //"tumara", "hindu", "hindi", "english"
                // "aag", "atulya", "ataah",
                //"adeergha",  "angootha", "ankan", "ankaganit"
                );

    //Translit tr = new Translit("../../tests/train-crf50K.model");
    for (String word : words) {
        //obj.transliterateWord(word);
    String transliterations = "boo";
        //tr.getTransliterations(word);
        System.out.println(word + ":" + transliterations);
    }
    //tr.delete();
}

}

我得到了相同的valgrind错误

0 个答案:

没有答案