gcc/libjava/gnu/gcj/runtime/natVMClassLoader.cc
Tom Tromey 3fd8010046 PR libgcj/12016, PR libgcj/18405, PR libgcj/17738:
* java/lang/Package.java (getPackages): Use VMClassLoader when
	appropriate.
	(getPackage): Likewise.
	* prims.cc (_Jv_CreateJavaVM): Call
	_Jv_RegisterBootstrapPackages.
	* include/jvm.h (_Jv_RegisterBootstrapPackages): Declare.
	* java/lang/VMClassLoader.java (getPackage): Rewrote.
	(getPackages): Likewise.
	(definedPackages): New field.
	(definePackageForNative): New method.
	* java/lang/Class.h (_Jv_FindClassInCache): Updated.
	* java/lang/natVMClassLoader.cc (loadClass): Updated.
	* defineclass.cc (handleClassBegin): Use
	ClassLoader.findLoadedClass.
	* java/lang/natClassLoader.cc (_Jv_RegisterInitiatingLoader):
	Rewrote.
	(struct _Jv_LoaderInfo): Removed.
	(initiated_classes): Likewise.
	(_Jv_UnregisterClass): Don't use initiated_classes.
	(_Jv_FindClassInCache): Likewise.  Removed 'loader' argument.
	(_Jv_FindClass): Register classes found during boostrap.
	(BOOTSTRAP_CLASS_LIST_SIZE): New define.
	(bootstrap_class_list): New global.
	(bootstrap_index): Likewise.
	(_Jv_RegisterBootstrapPackages): New function.
	* gnu/gcj/runtime/natVMClassLoader.cc (findClass): Call
	definePackageForNative.
	(findClass): Updated.
	* gnu/gcj/runtime/VMClassLoader.java (definePackageForNative):
	New method.

From-SVN: r93155
2005-01-10 19:39:26 +00:00

80 lines
2.2 KiB
C++

// Native code for VMClassLoader
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <gcj/cni.h>
#include <jvm.h>
#include <gnu/gcj/runtime/VMClassLoader.h>
#include <java/lang/Class.h>
#include <java/lang/StringBuffer.h>
#include <java/net/URLClassLoader.h>
#include <java/lang/Runtime.h>
#include <java/util/HashSet.h>
jclass
gnu::gcj::runtime::VMClassLoader::findClass (jstring name)
{
_Jv_Utf8Const *name_u = _Jv_makeUtf8Const (name);
jclass klass = _Jv_FindClassInCache (name_u);
if (! klass && lib_control != LIB_NEVER)
{
// Turn `gnu.pkg.quux' into `lib-gnu-pkg-quux'. Then search for
// a module named (eg, on Linux) `lib-gnu-pkg-quux.so', followed
// by `lib-gnu-pkg.so' and `lib-gnu.so'. If loading one of
// these causes the class to appear in the cache, then use it.
java::lang::StringBuffer *sb = new java::lang::StringBuffer (JvNewStringLatin1("lib-"));
// Skip inner classes
jstring cn;
jint ci = name->indexOf('$');
if (ci == -1)
cn = name;
else
cn = name->substring (0, ci);
jstring so_base_name = (sb->append (cn)->toString ())->replace ('.', '-');
using namespace ::java::lang;
Runtime *rt = Runtime::getRuntime();
// Compare against `3' because that is the length of "lib".
while (! klass && so_base_name && so_base_name->length() > 3)
{
if (lib_control == LIB_CACHE)
{
// If we've already tried this name, we're done.
if (tried_libraries->contains(so_base_name))
break;
tried_libraries->add(so_base_name);
}
jboolean loaded = rt->loadLibraryInternal (so_base_name);
jint nd = so_base_name->lastIndexOf ('-');
if (nd == -1)
so_base_name = NULL;
else
so_base_name = so_base_name->substring (0, nd);
if (loaded)
klass = _Jv_FindClassInCache (name_u);
}
}
// Either define the package, or try loading using the interpreter.
if (klass)
definePackageForNative(name);
else
klass = java::net::URLClassLoader::findClass (name);
return klass;
}