1 // Native code for VMClassLoader
3 /* Copyright (C) 2002 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
16 #include <gnu/gcj/runtime/VMClassLoader.h>
17 #include <java/lang/Class.h>
18 #include <java/lang/StringBuffer.h>
19 #include <java/net/URLClassLoader.h>
20 #include <java/lang/Runtime.h>
23 gnu::gcj::runtime::VMClassLoader::findClass (jstring name
)
25 _Jv_Utf8Const
*name_u
= _Jv_makeUtf8Const (name
);
26 jclass klass
= _Jv_FindClassInCache (name_u
, 0);
30 // Turn `gnu.pkg.quux' into `lib-gnu-pkg-quux'. Then search for
31 // a module named (eg, on Linux) `lib-gnu-pkg-quux.so', followed
32 // by `lib-gnu-pkg.so' and `lib-gnu.so'. If loading one of
33 // these causes the class to appear in the cache, then use it.
34 java::lang::StringBuffer
*sb
= new java::lang::StringBuffer (JvNewStringLatin1("lib-"));
37 jint ci
= name
->indexOf('$');
41 cn
= name
->substring (0, ci
);
42 jstring so_base_name
= (sb
->append (cn
)->toString ())->replace ('.', '-');
44 // Compare against `3' because that is the length of "lib".
45 while (! klass
&& so_base_name
&& so_base_name
->length() > 3)
47 using namespace ::java::lang
;
48 Runtime
*rt
= Runtime::getRuntime();
49 jboolean loaded
= rt
->loadLibraryInternal (so_base_name
);
51 jint nd
= so_base_name
->lastIndexOf ('-');
55 so_base_name
= so_base_name
->substring (0, nd
);
58 klass
= _Jv_FindClassInCache (name_u
, 0);
62 // Now try loading using the interpreter.
64 klass
= java::net::URLClassLoader::findClass (name
);